I have a simple regular expression that validates a middle
name:
<cfset valid = REFind("^[A-Za-z' ]*$",FORM.middlename)>
I want the middle name to be optional, but when I try a blank
entry in the form, the REFind returns 0. I though the star (*)
would solve the problem but I can't seem to get it to work.
On Wed, 27 Sep 2006 15:45:09 +0000 (UTC), cmschofield wrote:
> I have a simple regular expression that validates a
middle name:
> <cfset valid = REFind("^[A-Za-z'
]*$",FORM.middlename)>
>
> I want the middle name to be optional, but when I try a
blank entry in the
> form, the REFind returns 0.
Right. REFind() returns the character position at which the
match starts,
right? So which character position would the match start at
in a
zero-length string?
The problem here is there's no way of distinguishing between
"no match" and
"match at position zero".
> Thanks Adam. I'll just use the Java method. The more I
learn about the CF regular expression methods, the more I hate
them.
I think they're fine (and much better in CFMX than in older
versions).
REFIND() does exactly what it claims it does, and indeed was
giving you the
correct answer, remember ;-)
CF and Java obviously use the same regex processor, so they
have the same
shortcomings as far as what regex "grammar" they understand.
For example
Perl's regexes do a whole bunch of stuff that neither Java
nor CF can do,
and I presume PHP is the same.
I guess there are probably third-party Java classes out there
that cover
more options, having said that (I've never had need to
investigate yet).
I'd probably approach your situation in two steps: