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.
-
4SO 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 Answers
Use regex to validate the number being input. Try googling before you post.

- 6,166
- 10
- 46
- 75
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.

- 2,483
- 5
- 23
- 38
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.

- 12,037
- 3
- 33
- 51