티스토리 뷰

Skill/html js css

js validation

진열사랑 2025. 1. 3. 13:26

/**------------------------------------------------------------
* 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">

'Skill > html js css' 카테고리의 다른 글

js 속성 선택자  (0) 2025.01.03
inputmask 사용예  (0) 2025.01.03
유용한 js 라이브러리  (0) 2025.01.03
bootstrap 이벤트  (0) 2024.12.17
jquery 모음  (0) 2024.12.17
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함