I am trying to validate a form using the regex found here http://regexlib.com/ . What I'm trying to do is filter out all the characters except az, commas and apostrophes. If I use this code:
<cfinput name="FirstName" type="text" class="fieldwidth" maxlength="90" required="yes" validateat="onsubmit,onserver" message="Please ensure you give your First Name and it does not contain any special characters except hyphens or apostrophes." validate="regular_expression" pattern="^([a-zA-Z'-]+)$" />
I get the following error: Unmatched [] in the expression. I realized that this applies to the apostrophe because it works if I use this code (but don't allow apostrophes):
<cfinput name="FirstName" type="text" class="fieldwidth" maxlength="90" required="yes" validateat="onsubmit,onserver" message="Please ensure you give your First Name and it does not contain any special characters except hyphens or apostrophes." validate="regular_expression" pattern="^([a-zA-Z-]+)$" />
So, I am wondering if there is a special way to avoid apostrophes when using regular expressions?
EDIT
I think I found where the problem arises (thanks xanatos), I donβt know how to fix it. Basically, CF generates a hidden field to validate the field as follows:
<input type='hidden' name='FirstName_CFFORMREGEX' value='^([a-zA-Z'-]+)$'>
Since it uses single apostrophes rather than speech marks around the value, it interprets the apostrophe as the end of the value.
Kristian82
source share