File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes how to make text field to accept only alphabets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to make text field to accept only alphabets" Watch "how to make text field to accept only alphabets" New topic
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: 1167
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: how to make text field to accept only alphabets
 
Similar Threads
How to make text field to accept only alphabets.
Validate textbox to accept only numeric values.
How to make text field to accept only alphabets
javascript regular expression related problem.
Amout validation