File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "validation check phone field" Watch "validation check phone field" New topic

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: 15100

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 8 API documentation
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
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.
I agree. Here's the link:
subject: validation check phone field
jQuery in Action, 3rd edition