• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to make text field to accept only alphabets

 
Shrikanth Nekkanti
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tarun Yadav
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic