This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes validation check phone field 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 "validation check phone field" Watch "validation check phone field" New topic
Author

validation check phone field

Li Jenny
Ranch Hand

Joined: Apr 19, 2010
Posts: 57
how can i check the textbox only contain numeric ,not letter such as phone no field in javascript
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

You can use regular expressions for this.

Googling for javascript phone number validation gives some links that look interesting.

(Note: JavaScript doesn't have anything to do with Java. We do have a forum about HTML and JavaScript here, so I've moved your question there for you).


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41068
    
  43
Regular expressions would be one way. But be aware that many people enter phone numbers containing characters such as + / - ( ) or . - you need to account for that in some way. Or you can just remove everything that is not a number after they've entered it. Of course, "+491234567890" is not the same phone number as "491234567890", just in case you need to handle international numbers.


Ping & DNS - my free Android networking tools app
 
 
subject: validation check phone field
 
Similar Threads
implementing ActionListener and ItemListener
need help in handling HttpServletRequest
phonebook acces
email and phone numbers check in the text field
validating forms