Thursday, February 21, 2013

jQuery Validiate Custome Rules

Followings are the few custom rule to validate German telephone and zip followed by city.

German telephone:

jQuery.validator.addMethod("checkTelephone", function(value, element) {return this.optional(element) || /^([\+][0-9]{1,3}[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/] {3,20})    ((x|ext|extension)[ ]?[0-9]{1,4})?$/.test(value);
});

zip followed by city:

jQuery.validator.addMethod("checkPlzort", function(value, element) {return this.optional(element) || /^(?!01000|99999)(0[1-9]\d{3}|[1-9]\d{4})([a-zA-Zäöüß  \s\d()/\-)]+?)$/.test(value);
 });