Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mobile number validation in java script

 
P Arunkumar
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1110
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2586
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to our 'HTML, CSS and JavaScript' forum.
 
Ravi Majety
Ranch Hand
Posts: 59
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1110
Eclipse IDE Oracle VI Editor
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
P Arunkumar
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic