1

Using bassistance.de's jQuery validation plugin, the validation do not always work, especially when an input that's initially been validated has its values removed.

The form will pass the validation test with the missing input, and the following error is also seen in the JS console.

Error

enter image description here

jQuery lib

<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.js"></script>

Form

<form id="payment-form" class="payment-form" method="POST" action="/checkout-process">
    <fieldset>
        <legend>Customer Info</legend>
        <label>Full Name</label>
        <input type="text" name="first_name" placeholder="First Name">
        <input type="text" name="last_name" placeholder="Last Name">
        <label>Email</label>
        <input type="text" name="email" placeholder="[email protected]">
        <label>Phone</label>
        <input type="text" name="phone" placeholder="Phone">
    </fieldset>
</form>

JS

$(function($) {

    // Validation
    $('#payment-form').validate({
        rules: {
            first_name: "required",
            last_name: "required",
            email: {
                required: true,
                email: true
            },
            phone: {
                required: true,
                phone: true
            }
        },

        errorClass: 'alert alert-error'
    });

});
5
  • use a non minified version of the library while debugging, so that we can get the correct line number Commented Jul 29, 2013 at 3:04
  • I've made the change.. its on line 549 Commented Jul 29, 2013 at 3:05
  • 1
    seems fine jsfiddle.net/arunpjohny/QFWB4/1 Commented Jul 29, 2013 at 3:06
  • it looks like a problem with one of the specified rules, did you include the additional-methods.js also Commented Jul 29, 2013 at 3:09
  • line 549 says result = $.validator.methods[method].call( this, val, element, rule.parameters ); which means one of the rule name you have specified is invalid Commented Jul 29, 2013 at 3:10

2 Answers 2

2

The problem is with the rule phone, there is no validation method called phone.

If you include the additional-methods.js, then you can have phone validation rules like phoneUS, phoneUK, mobileUK, phoneNL etc

Ex:

$(function($) {

    // Validation
    $('#payment-form').validate({
        rules: {
            first_name: "required",
            last_name: "required",
            email: {
                required: true,
                email: true
            },
            phone: {
                required: true,
                phoneUS: true
            }
        },

        errorClass: 'alert alert-error'
    });

});

If none of these matches your requirement, then you may have to write a custom rule

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

2 Comments

Thanks that solved the problem... I cant seem to find a link to all the rules that comes along with the plugin
@Nyxynyx I don't think the additional-methods.js is documented properly... any way you can easily read that file to see all the available rules
0

Please check the links and make sure it resolves the exact url.

Comments

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.