jquery validate addon functions


$(document).ready(function(){
    
   
   jQuery.validator.addMethod(
        "intgrt0",
        function(value, element) {
            return value.match(/^([1-9]{1}[0-9]*)$/);
        },
        "Please enter a quantity greater then 0 & it should not start with 0"
    );
    
    /*email*/
     jQuery.validator.addMethod(
        "emailproper",
        function(value, element) {
        return value.match(/^[A-Za-z0-9]+\w*([\.-]\w+)*@\w+([\.][A-Za-z0-9]{2,3})+$/);
           
        },
        "Please enter proper email like abc@domain.com"
    );
    
    /*Letters only*/
    jQuery.validator.addMethod("lettersonly", function(value, element) {
        return this.optional(element) || /^[a-zA-Z\s]+$/i.test(value);
    }, "Please enter Characters only"); 
    
    jQuery.validator.addMethod("special_numbers", function(value, element) {
        return this.optional(element) || /^[0-9]+([\-][0-9]+)*$/i.test(value);
    }, "Please enter proper details (only 0 to 9 and - allowed)"); 
   });//doc ready


usage
 var test= $("#addOrder").validate({
                        rules: {
                            company_name: "required",
                            contact_name: "required"
                        }
                    }).form();
                    if(!test)
                        return false;
                    break;

Share on Facebook




About Pragnesh Karia

Pragnesh Karia, Open Source Enthusiast, Software Professional, Software Developer, Technical Lead ,Magento, Joomla ,Joomla LMS , Moodel LMS ,PHP ,Mysql, Ajax, Javascript, Jquery, Linux, Fan of Open Sources , Annet Technologies , SEO Analyst , Mootools