Hi,
can somebody help me valditing an cfinput field using regular expressions?
First digit must be a number or "R".
Digit 2-15 can be everything without special characters. Digit 2-15 can also be empty.
I try this, but it doesn't work (Sorry I'm a beginner using regex).
<cfinput type="text" name="field1" required="yes" validate="regular_expression" pattern="[0-9Rr][0-9a-zA-Z]*" maxlength="15">
Thank you in advice!
Claudia
You haven't told your regex to match the entire string, so it will "pass"
any string that has your match anywhere within it, so like as long as it's
got an R or a digit in it: it's OK.
To tell it to match the entire string, anchor it to the start and end of the
string with ^ and $ respectively.
Regular expression syntax: Using special characters
--
Adam
Your regex is basically correct. All you need to do is to say "and make
sure it matches the entire string", not just "any substring", like you
currently have.
To do this, one forces the regex to match from the beginning of the string,
right through to the end of the string.
So, for example a regex of "ant" would match "ant" or "pants" or
"elephant". However "^ant$" would not match "pants" or "elephant" because
the "^" means "match the beginning of the string", and "$" means "match the
end of the string". In effect this makes it so your regex must match the
entire string.
Make sense?
--
Adam
North America
Europe, Middle East and Africa
Asia Pacific