Solved

cfinput reg ex string validation issue with alpha only

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

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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