• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

mobile number validation in java script

 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2662
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to our 'HTML, CSS and JavaScript' forum.
 
Ranch Hand
Posts: 59
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic