Solved

cfinput reg ex string validation issue with alpha only

Posted on 2008-10-31
4
373 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
Comment Utility
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
Comment Utility
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
Comment Utility
try pattern="[[:alpha:]]"


0
 
LVL 8

Expert Comment

by:eszaq
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now