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 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "validation" Watch "validation" New topic


Saurabh Naik
Ranch Hand

Joined: Apr 24, 2008
Posts: 87
How to make validation for allowing only numbers. suppose in my form there is field named phone no. so numbers should be allowed in it and not text.
so is there any built in function in java script ? or how to make use of regex in this case .

SCJP 6 (88%), SCWCD 5 (78%), preparing for SCBCD
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33098

There are many examples online. Have you tried searching yet?

A quick search showed me a regular expression in JavaScript for zip code. Phone numbers are similar - logic varies by region though.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874

Start here for regex basics.

As Jeanne pointed out, phone number varies in region-wise , code your regex pattern and test() like the code above.
I agree. Here's the link:
subject: validation
It's not a secret anymore!