-5

I want to validate the phone number whose length should be between 8 and 15 and might be present one + symbol infront of the number. That means +56789765908 and 7612345678909 are valid phone number. Please help me.

Kara
  • 6,115
  • 16
  • 50
  • 57
Bappa
  • 799
  • 1
  • 9
  • 17
  • 4
    SO is a place for help with your code, not a place for people to do the task for you in its entirety. Show us waht you've tried, or at least looked into. – Mitya Jul 27 '12 at 13:41

4 Answers4

0

Use regex to validate the number being input. Try googling before you post.

RonnyKnoxville
  • 6,166
  • 10
  • 46
  • 75
0

Jquery has a validator plugin that has a phone number validation method build in. If their built in one doesn't do that job for you, then you can define custom validation methods. You use their Min and Max to assure the phone # is the correct length and then use a regex to test for an optional "+" and all digits.

((+|)\d*) try using that.

http://docs.jquery.com/Plugins/Validation

http://regexpal.com/ for testing regex. Very handy tool.

spots
  • 2,483
  • 5
  • 23
  • 38
0

I recommend using <input type="tel">. This is a new feature of HTML5. It is the simplest, and creates the best user experience in browsers that implement this new functionality (especially on mobile devices).

You can also use JavaScript to detect whether or not the visitor's browser implements telephone number input and fall back to using jQuery or a regex or similar when it doesn't. Modernizr is a readily available JavaScript library for detecting features implemented by the browser.

dsh
  • 12,037
  • 3
  • 33
  • 51
0

I'd advise against stuff like this since there's almost always a country where the phone numbers won't match the validation, but here is the regex that matches your request

^\+?[0-9]{8,15}$
dsh
  • 12,037
  • 3
  • 33
  • 51
Luka
  • 341
  • 2
  • 11