cfinput-i want user to enter only 4 digits not less and not more then 4 digits in input field

Hi,
I want people to enter 4 digits in to input field.  I am using this code.  

<cfinput name="ssn" type="text" required="yes" maxlength="4" validate="regular_expression" pattern="[0-9][0-9][0-9][0-9]" message="Only last 4 digits of SSN" >

Can somebody help me to understand what i am doing wrong.
Thanks
adnankAsked:
Who is Participating?
 
erikTsomikConnect With a Mentor System Architect, CF programmer Commented:
try to add validateat
<cfinput name="ssn" type="text" required="yes" maxlength="4" range="0,9999" validate="regular_expression" pattern="[0-9][0-9][0-9][0-9]" message="Only last 4 digits of SSN" validateat="onblur">
0
 
pinaldaveCommented:
<cfinput name="ssn" type="text" required="yes" maxlength="4" range="0,9999" validate="regular_expression" pattern="[0-9][0-9][0-9][0-9]" message="Only last 4 digits of SSN" >
0
 
erikTsomikSystem Architect, CF programmer Commented:
I agree with
pinaldave:
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
adnankAuthor Commented:
Same thing.  I still can enter only one digit and get the result. If i enter 2 in input field.  it will show me all the result which start with 2.  
0
 
duncancummingCommented:
what about pattern="[0-9]{4}"  ?

i'd probably take the range off, i suspect that might be overriding the regex part here.  
0
 
adnankAuthor Commented:
Adding vaildateat="onblur" didn't work.
However, i solve the problem with length function.
<cfif #len(form.ssn)# LT 4>
          <cfoutput><h2>Please enter last 4 digits of SSN</h2></cfoutput>
           <cfabort>
</cfif>

Thanks
0
 
erikTsomikSystem Architect, CF programmer Commented:
Are you using cfform

0
All Courses

From novice to tech pro — start learning today.