asaworker
asked on
cfinput reg ex string validation issue with alpha only
<cfinput type="text" name="screenname" id="screenname" validate="regular_expressi on" 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?
isn't working. I keep getting the javascript to popup even when string is correct. What am I doing wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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)