Q:

Add a method jQuery Validation

how can I write a new method using the addMethod() method? I want to validate a phone number that it starts with a 0 and its length is 10. What i've tried so far:  
function cell(element, value){
            if (!/^[0]\d{9}$/.test(element).val()) {
                return false;
            }
            else {
                return true;
            }
        }

        $.validator.addMethod("cell", cell, "This phone number is incorrect");

and:
$("#signupForm").validate({
    rules: {
        cell: {
            required: true,
            digits: true,
            cell: true
        }
    }
})

And in the messages am I supposed to write a message for 'cell' to? Thanks!

A:

add custom method this way-
$.validator.addMethod("cell", function (value, element) {
        if (!/^[0]\d{9}$/.test(element).val()) {
            return false;
        }
        else {
            return true;
        }
}, 'This phone number is incorrect');

and your validation method-
$("#signupForm").validate({
    rules: {
        cell: {
            required: true,
            digits: true,
            cell: true
        }
    }
});

it should work.

