Solved

cfinput reg ex string validation issue with alpha only

Posted on 2008-10-31
4
376 Views
Last Modified: 2013-12-24
<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?
0
Comment
Question by:asaworker
  • 3
4 Comments
 
LVL 8

Accepted Solution

by:
eszaq earned 500 total points
ID: 22851382
Look at your regex pattern:
^[a-zA-Z]?$

^ denotes start of the string
$ denotes end of the string
? stands for 0 or 1 of characters from accepted range

try to specify length of your string with {min,max}:
^[a-zA-Z]{5,20}$




0
 
LVL 8

Expert Comment

by:eszaq
ID: 22851412
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
0
 
LVL 16

Expert Comment

by:duncancumming
ID: 22856096
try pattern="[[:alpha:]]"


0
 
LVL 8

Expert Comment

by:eszaq
ID: 22858149
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)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question