js validation
/**------------------------------------------------------------
* validation
------------------------------------------------------------*/
$(function() {
$.validator.addMethod("notEqualTo", function(value, element, param) {
return this.optional(element) || value != $(param).val();
}, "Please specify a different value.");
$.validator.addMethod("dupId", function(value, element, param) {
return this.optional(element) || "N" != $(param).val();
}, "Please specify a different Id or No.");
$.validator.addMethod("alphaNumeric", function(value, element, param) {
return this.optional(element) || /^[a-zA-Z0-9]+$/.test(value);
}, "Please input alphanumeric characters only for Id.");
$.validator.addMethod("passwordCheck", function(value, element, param) {
return this.optional(element) || /^.*(?=.*\d)(?=.*[a-zA-Z])(?=.*[!@#$%^&+=]).*$/.test(value);
}, "Please enter a valid password value.(character + number + special character)");
$.validator.addMethod("pwCheckConsecChars", function(value, element, param) {
return this.optional(element) || !/(.)\1{2,}/.test(value);
}, "The password must not contain 3 consecutive identical characters.");
$.validator.addMethod("rate", function(value, element, param) {
return this.optional(element) || /^(?=.)(?:[1-9]\d{0,2})?(?:\.\d{1,2})?$/.test(value);
}, "Please enter a valid rate value.(decimal point is allowed up to 2)");
$.validator.addMethod("money", function(value, element, param) {
return this.optional(element) || /^(?=.)(?:[1-9]\d{0,18})?(?:\.\d{1,2})?$/.test(value) || value <= 0;
}, "Please enter a valid rate value.(decimal point is allowed up to 2)");
$.validator.addMethod("noKorean", function(value, element, param) {
return this.optional(element) || !/[\u3131-\u314e|\u314f-\u3163|\uac00-\ud7a3]/.test(value);
}, "Korean is not allowed in this field.");
$.validator.addMethod("yyyymmdd", function(value, element, param) {
return this.optional(element) || !/^[12][0-9]{3}[01][0-9][0-3][0-9]$/.test(value);
}, "Invalid date format.");
$.validator.addMethod("celNo", function(value, element, param) {
return this.optional(element) || /^[0-9-]{2,20}$/.test(value);
}, "Please input numeric and '-' characters only for cell phone number.");
});
사용법
<input celno="true">