Solved

cfinput reg ex string validation issue with alpha only

Posted on 2008-10-31
4
378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

690 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