How to use JQuery Custom validation method to validate phone number
I wanted to validate a phone number using jQuery custom validation method.I tried to write a method for that but it didn't work .Can anyone help me to find the error of this code .As I'm new to this language I don't know much about jQuery. here is my code
- $(document).ready(function () {
- jQuery.validator.addMethod('phonenu', function(value, element) {
- if(element.value != 10 && element.value == isNaN)
- {
- return false;
- }
- else
- { return true;
-
- }, 'Invalid phone number'});
- $('#myform').validate({
- rules: {
- phone: {
- required: true
- phonenu: true,
-
- }
- }
- });
- });
html code
- <form id="myform">
- <input name="phone" type="text" />
- <input type="submit" />
- </form>