'custom regex'에 해당되는 글 1건

  1. 2013.03.21 jQuery Validate - custom regex
2013.03.21 17:29

jQuery Validate - custom regex

Validator

jQuery.validator.addMethod(          

"regex",

    function(value, element, regexp) {

        if (regexp.constructor != RegExp)

            regexp = new RegExp(regexp);

        else if (regexp.global)

            regexp.lastIndex = 0;

        return this.optional(element) || regexp.test(value);

}, "검증 실패 메세지");


Validate

$("#form_id").validate({
    rules : {
        name : { required : true },
        code : {required : false, regex : "^[cC][a-zA-Z0-9]{5}$"}
    },
    submitHandler : submitHandler
});



[출처] JQuery validate: How to add a rule for regular expression validation?

Trackback 0 Comment 0