| Author |
how to make text field to accept only alphabets
|
Shrikanth Nekkanti
Ranch Hand
Joined: Jul 12, 2007
Posts: 48
|
|
I have a First name Text field.I want to make this text field to accept only characters. How to make this text field to restrict accepting numbers and special characters.
|
 |
Tarun Yadav
Ranch Hand
Joined: Sep 20, 2007
Posts: 134
|
|
Originally posted by Shrikanth Nekkanti: I have a First name Text field.I want to make this text field to accept only characters. How to make this text field to restrict accepting numbers and special characters.
This is JavaScript query, not JSP. Google "javascript restrict input" and you'll get lots of discussions, scripts and other related resources to help you with this. Here's a quick link: http://www.rgagnon.com/jsdetails/js-0084.html, it works for alphanumeric input but you can easily modify the regex to only leave out the numbers also.
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
Originally posted by Tarun Yadav: This is JavaScript query, not JSP. Google "javascript restrict input" and you'll get lots of discussions, scripts and other related resources to help you with this. Here's a quick link: http://www.rgagnon.com/jsdetails/js-0084.html, it works for alphanumeric input but you can easily modify the regex to only leave out the numbers also.
If it is important that only alpha characters get through, then this should also be validated on the server. Starting with version 1.4, Java ships with a very robust regular expression package. Start by looking at the String.matches method.
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
Tarun Yadav
Ranch Hand
Joined: Sep 20, 2007
Posts: 134
|
|
Originally posted by Ben Souther: If it is important that only alpha characters get through, then this should also be validated on the server. Starting with version 1.4, Java ships with a very robust regular expression package. Start by looking at the String.matches method.
True, should've mentioned that. Got to addressing the OPs immediate requirement :p
|
 |
Dan Drillich
Ranch Hand
Joined: Jul 09, 2001
Posts: 1121
|
|
|
As we spoke about at Delete all invalid characters of a string the optimal solution, is to enforce your logic in each of the three tiers of the system.
|
William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
|
 |
 |
|
|
subject: how to make text field to accept only alphabets
|
|
|