Solved

cfinput reg ex string validation issue with alpha only

Posted on 2008-10-31
4
374 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

Free camera licenses with purchase of My Cloud NAS

Milestone Arcus software is compatible with thousands of industry-leading cameras for added flexibility. Upon installation on your My Cloud NAS, you will receive two (2) camera licenses already enabled in the software. And for a limited time, get additional camera licenses FREE.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to Eclipse 16 117
segregating a list into two lists 4 65
DNS, website, godaddy 6 76
paging 3 37
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

23 Experts available now in Live!

Get 1:1 Help Now