edit syntax and issue
Kenneth Brody
kenbrody at spamcop.net
Wed Jul 31 08:52:16 PDT 2013
On 7/31/2013 10:21 AM, scooter6 at gmail.com wrote:
> I'm trying to get our address fields to be more USPS compliant, so I want
> to 'remove' a comma or period if someone inputs them
>
> So far I have :
>
> {{A} | {N} | [!","!] | [!"."!]}
>
> In testing this edit, if I pust something like: 1234, it changes it
> to just: 1234 (perfect)
> If I put 1234 Main St, Apt A I get edit failed
>
> If I put 1234. (period) I get edit failed..... shouldn't I at least
> get the same result using the period, shouldn't it remove it like it does
> with 1234, (comma) ??
>
> How can I make the field NOT allow a comma or a period but can accept
> all letters and numbers
Two problems:
(1) Your edit won't allow any imbedded spaces, so even "123 Main" would fail.
(2) What about other punctuation? What do you want to do with things such
as hyphens?
Assuming you want only letters/numbers/spaces, and want to accept, but
eliminate, commas and periods:
{{A} | {N} | {" "} | !","! | !"."! }
The addition of accepting spaces should be obvious as to how it works.
However, the main change is replacing:
[!","!] | [!"."!]
with:
!","! | !"."!
This is crucial to getting the "remove periods" to work. You are probably
asking "why?"
Time to learn a little German and conduct a "gedankenexperiment" -- become
the filePro edit engine...
==========
You are given the (slightly modified) original edit
{{A} | {N} | {" "} | [!","!] | [!"."!]}
and the input string
123 Main, Apt. 17
The initial character "1" does not pass the "A" edit, causing "{A}" to fail.
The edit then tries "{N}", which accepts the "1" as well as the subsequent
"2" and "3". However, the space fails, and the "{N}" ends, having accepted
"123". The entire or-series has now succeeded, causing the edit engine to
return to the outermost "{...}" pair.
The next character, the space, fails "A" and "N", and is then accepted by
the " " edit. Since the next character, "M", fails to pass the " " edit,
the {" "} ends, the or-series succeeds, and control again returns to the
outermost "{...}" pair.
Repeat for "Main", which will be accepted by "{A}", stopping at the comma.
The comma fails the A, N, and " " edits. It does, however, pass the next
part of the edit -- [!","!] -- causing it to be deleted, and control again
returning to the outermost "{...}".
Repeat for " " and "Apt".
Now, for the part as to why the above fails at the "."...
We have the character ".". It fails A. It fails N. It fails " ".
However, contrary to what you might expect, the period does, in fact, pass
the next part of the edit -- [!","!]
"How can a period possibly pass that edit?" I can hear you screaming.
Simple -- the "accept or delete a comma" is *optional*. You have told
filePro, "if there is a comma, delete it, but if there isn't a comma, that's
okay too". The or-series is satisfied, and control once again returns to
the outermost "{...}".
The period never gets accepted, and it never gets deleted. Hence, the edit
failure.
By removing the "optional" part of the edit, you tell filePro that if there
isn't a comma to delete, fail that part of the or-series, and continue on,
at which point the accept-or-delete the period portion of the edit kicks in,
deleting the period, satisfying the or-series and, as always, returns
control to the outermost "{...}".
At which point, the edit continues on to the " ", the "17", and the trailing
spaces, as explained above. The entire field has now been accepted (with
the appropriate characters deleted), and the edit has passed.
==========
Now, as to my question (2) above... What about other punctuation? For
example, the hyphen and slash in:
27-1/2 sixth st.
Your edit will fail on anything that contains any punctuation other than
commas and periods.
If you want to accept everything *except* commas and periods, the edit can
be simplified to:
{ !","! | !"."! | * }
You can then decide on specific characters you want to delete in addition to
comma and period, and accept everything else as-is. For example:
{ !","! | !"."! | !"?"! | * }
--
Kenneth Brody
More information about the Filepro-list
mailing list