Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

preventing numbers from a text area

Status
Not open for further replies.

mochalova

MIS
Sep 20, 2007
15
US
Quick question from a JS newbie:

I have a form which does some validation ie makes sure you enter first name, last name etc. However I have a textarea which is not required but if the user does fill it out, I need to prevent the user from entering a 5 or more consecutive numbers. So you can enter 1234 but not 12345 so not more than 4 consecutive numbers.

Please any help would be great.

Thanks
 
what code do you already have?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 

My present validation is being done via Coldfusion, but I would need JS to handle the textarea validation for me.
Thanks

<body>
<cfform name="form" action="act.cfm" method="post">
<table>
<tr>
<td> <cfinput type="text" name="FIRST_NAME" value="" message="Please type in your first name." validate="regular_expression" pattern="[A-Za-z0-9]+"> </td>
<td> <cfinput type="text" name="LAST_NAME" value="" message="Please type in your last name." validate="regular_expression" pattern="[A-Za-z0-9]+"> </td>
</tr>
<tr>
<td class="small"> Email Address where you can be reached <font class="required">*</font> </td>
<td class="small"> Billing Phone Number <font class="required">*</font> </td>
</tr>
<tr>
<td> <cfinput type="text" name="EMAIL_ADDR" value="" message="Please type in your email address." validate="regular_expression" pattern="[A-Za-z0-9]+"> </td>
<td> <cfinput type="text" name="BILL_PHONE" value="" message="Please type in your phone number in xxx-xxx-xxxx format." validate="telephone"> </td>
</tr>
<tr>
<td colspan="2" class="small"> Comments<textarea cols="60" rows="10" name="COMMENTS"></textarea> </td>
</tr></table>
</cfform>
</body>
 
I can see you put in much effort into the code you posted. Perhaps a reg expression something like this
Code:
[0-9]\{5\}
would help you.
 
TYhe problem you may run into with the javascript verification is that if you use the onkeypress, onblur, or onkeyup events is that you get sent to the of the text if you verify incorrectly. Example you are typing some text like "I am the best" and you make a mistake and would like to replace I with "You" and while typing "You" an invalid key is pressed. The validation kicks in and works to prevent such chars but the user is sent to the end of the string not where he started to edit. I use this same method but on my case it does not really matter because of the nature of the input.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top