Copy link to clipboard
Copied
Can anyone tell me why my regex is not working on my cfinput textbox please. I only want to allow a-z as available charactors to enter and the below code fails.
<cfinput type="text"
id="surname"
name="surname"
class="txt"
title="Surname"
value="#presentsurname#"
validate="regex"
pattern="[a-z]"
message="Please enter a valid Surname."
maxlength="60" />
If i type in $$$ then the regex is flagged up and I get the error message displayed.
Although if I type in a$$, I get no error message.
Thanks,
G
Try putting the start and end chars in, ie ^ at the start and $ at the end to make sure it's matching the entire string.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
That would only allow one character, try [a-z]+ to allow one or more.
Copy link to clipboard
Copied
Thanks for the quick replies guys, your really helpful and both regex examples you have given both work.
To cut a long story short I was give the following regex to use against my surname textbox, and I need to follow 'their' standards so I must use this pattern.
([A-Z'\-]*)|([A-Z'\-][A-Z '\-]*[A-Z'\-])
And this should only allow A-Z (in capitals) and any of the other special charactors that are mentioned in the regex.... Although this pattern is allowing me to enter A$$ and I do not understand why it is allowing the $ sign to be an enterable charactor when the dollar sign is not listed in the regex.
Copy link to clipboard
Copied
Try putting the start and end chars in, ie ^ at the start and $ at the end to make sure it's matching the entire string.
Copy link to clipboard
Copied
Looks like you found a fix,
There is a tool I use called RegexBuddy that helps me debug Regular Expressions in real time. Also has a gui to help you build a Regular expressions, thats how I started but now I can write them with no problems.