Journeyman CF
Validating Input with Regular Expressions
Have you ever wished CFINPUT provided a way to validate an e-mail address? Or were you frustrated that its telephone validation didn't allow parentheses around an area code among other such limitations? Well, your wish has been granted in a new, little-known feature of CF5.
Reader Feedback : Page 1 of 1
#2 |
Kris Symer commented on the 8 Apr 2005
My coworker and I refined the email script so it would work for upper and lowercase letters in an optional cfinput field (required="no"): pattern="^([_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*\.(([A-Za-z]{2,3})|(aero|AERO|coop|COOP|info|INFO|museum|MUSEUM|name|NAME)))?$" |
#1 |
charles arehart commented on the 1 Aug 2002
Folks, I have found that there were a couple of errors in the expressions offered here. Please use the following instead. For email: ^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name))$ For phone: ^((\(?[1-9][0-9][0-9]\)?)?\s?[1-9][0-9][0-9]\s?\d{4})?$ Sorry for the inconvenience. |