Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validation

 
Saurabh Naik
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
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 .
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34672
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic