Link to home
Start Free TrialLog in
Avatar of asaworker
asaworker

asked on

cfinput reg ex string validation issue with alpha only

<cfinput type="text" name="screenname" id="screenname" validate="regular_expression" pattern="^[a-zA-Z]?$" value="#name#" validateat="onsubmit, onserver" required="yes" size="20" maxlength="20" message="Please use 20 characters or less for your screen name." />

isn't working. I keep getting the javascript to popup even when string is correct. What am I doing wrong?
ASKER CERTIFIED SOLUTION
Avatar of eszaq
eszaq
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
what I actually tried to say by analyzing your regex pattern - the way you wrote it, it would only validate an empy string or one character long string
try pattern="[[:alpha:]]"


Of course  [[:alpha:]] can be used - it is an exact equivalent of [a-zA-Z]. But the problem with the code was caused by improper use of ^$? operators. Original regular expression pattern written by asaworker would only match one character long string of alpha characters (or empty string)