This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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: 14114
    
  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: 41586
    
  54
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
 
Consider Paul's rocket mass heater.
 
subject: validation check phone field