jquery.validation.js is not working in woocommerce checkout page form

jQuery("#woocommerce_checkout_form").validate({


     highlight: function(element) {
            (jQuery(element).parent()).parent().addClass("woocommerce-invalid");
            (jQuery(element).parent()).parent().removeClass("woocommerce-validated");
        },
    unhighlight: function(element) {
            (jQuery(element).parent()).parent().removeClass("woocommerce-invalid");
            (jQuery(element).parent()).parent().addClass("woocommerce-validated");
        },


    submitHandler: function(form) {
        jQuery.ajax({
                type: "POST",
                data:values,
                url: jQuery(form).attr('action'),
                success: function(data){
                    //alert('ajax load');
                    //window.location.href = "http://demo7.web.dev1.bl/wp-content/plugins/woocommerce/templates/checkout/checkout.php";
                }
            });

            return true;

        //jQuery(form).ajaxSubmit();
    },
     rules: {

        billing_phone: {
            required: true,
            minlength:10,
            maxlength:10,
            number: true,
        },

        billing_postcode: {
            required: true,
            minlength:6,
            maxlength:6,
            number: true
        },

        shipping_postcode: {
            required: true,
            minlength:6,
            maxlength:6,
            number: true
        }
    },

    messages: {        
    billing_phone: {
        required: "Enter Phone Number", 
        minlength:"Please 10 Digit Phone Number",
        maxlength:"Please 10 Digit Phone Number",           
        number: "Please enter a valid quantity"
      },
      billing_postcode: {
        required: "Enter Valid Zipcode", 
        minlength:"Please enter six digits Zipcode",
        maxlength:"Please enter six digits Zipcode",           
        number: "Please enter a valid Zipcode"
      },

      shipping_postcode: {
        required: "Enter Valid Zipcode", 
        minlength:"Please enter six digits Zipcode",
        maxlength:"Please enter six digits Zipcode",           
        number: "Please enter a valid Zipcode"
      }

    }

});

This is the code that I am using to add extra validations on zipcode and phone but even in the case of not match it submit the form to payment. Is it possible to prevent form submission and stays on the checkout page after error just like default validations wokrs.

Topic woocommerce-offtopic validation jquery Wordpress

Category Web


Prevent form submit on click submit button and force validate

$('#place_order').on('click', function(event) {
    event.preventDefault();
    if ( $('form.checkout.woocommerce-checkout').valid() ) {
        $('form.checkout.woocommerce-checkout').submit();
    }
});

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.