0

The following code results in the following error:

SyntaxError: Unexpected token ).

Any ideas?

$("#signupForm").validate({
    rules: {
        'entry[first_name]': "required",
        'answers[985575][answer]': "required",
        'answers[985574][answer]': {
        required: true,
        phoneUS: true
        },
        'entry[email]': {
        required: true,
        email: true
    }
    }});

1 Answer 1

2

The phoneUS is not a standard, built-in rule. So unless you have defined it, it won't work. As explained in the documentation you need to define it. They provide the following method that you need to include in order to define the phoneUS rule:

jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, ""); 
    return this.optional(element) || phone_number.length > 9 &&
        phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Please specify a valid phone number");

And here's a working live demo.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I had this in my code however I moved only part of the code and it was missing this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.