wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes mobile number validation in java script 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 "mobile number validation in java script" Watch "mobile number validation in java script" New topic
Author

mobile number validation in java script

P Arunkumar
Ranch Hand

Joined: Jan 05, 2012
Posts: 119
Hi

I need to validate my mobile number it wants to be in +91-1234567890 this format

If i enter 1234567890 its wants to show alert message your mobile wants to be in +91-1234567890 format
If i enter +9112345678901 its wants to show alert message your mobile wants to be in +91-1234567890 format
If i enter 9112345678901 its wants to show alert message your mobile wants to be in +91-1234567890 format

and then the correct mobile format +91-1234567890 wants to save in My sql database.

Please guide me


Thanks in advance.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

This is a javascript question!!! why are you asking in the database section.
You might get better results asking in a forum where people who know javascript might go.

All i can say is investigate regular expressions this is a very simple one
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

Moved to our 'HTML, CSS and JavaScript' forum.


OCUP UML fundamental and ITIL foundation
youtube channel
Ravi Majety
Ranch Hand

Joined: Feb 26, 2009
Posts: 59

Hi Arun

Please check this code.

Note :
1. Also make use of component level of validation to restrict the user to enter only numerics and characters "+" and "-"
2. If the application is india based then you can proceed with 91 as country code or keep an array of all country codes and change the validation accordingly.





Hope it solves your problem..


Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

or using regular expressions do it in 4 lines of code, but I am not telling you what the regex is, you need to have a stab at it yourself
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60773
    
  65

Regulare expressions are indeed the way to go for this type of activity. The type of code shown earlier should be avoided when much better alternatives exist.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
P Arunkumar
Ranch Hand

Joined: Jan 05, 2012
Posts: 119
Hi thanks for your advice i got idea through regular expression

my code is:



If you enter other than +91 it will show alert Message, by using this format we can change the input method for our convenient.

I think it will help for all.... Thank you.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Why don't you correct simple formatting problems for the user instead of saying it is an error? This will make your application more user friendly.




Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mobile number validation in java script
 
Similar Threads
validating phone number or email id totally through our app
Cleared SCBCD 91%
Passed with 91%
91%
Part 2 and 3 91 %