본문 바로가기

Java Script & Jquery

jquery Validate 처리

블로그를 하긴 해야하는데 귀찮아서...순서는 지켜지지않음ㅋㅋㅋ


우선 오늘 처리했던 validate 만들기


validate란 form태그의 값들을 전달할 때 해당 태그의 값들이 유효한지 체크하는 기능임!

이걸 사용하기 위해선 jquery.validate.min.js라는 태그를 넣어줘야함

<script type="text/javascript src="jquery.validate.min.js"></script>

validate는 기본적으로 지원하는것들이 있고, 기준을 본인이 정할수도 있음.


$.validator.addMethod(

"spaceCheck", //validate명

function (value, element) {

//검사하는 name태그의 value 중 공백이 없으면 true, 있으면 false리턴

//false 리턴 시 messages에 선언된 내용들 띄워줌

return $(element).val().indexOf(" ")=-1?true:false;

   }

);


$("#addWriteForm").validate({

submitHandler: function() {

//submit

},

rules:{

태그명1: {

required: true,    //필수조건

minlength: 1,    //최소길이

maxlength: 50,    //최대길이

spaceCheck: true    //내가 추가한 validate 메소드

},

태그명2: {

required: true,

spaceCheck: true

},

태그명3: {

required: true

},

},

messages:{

태그명1: {

required:"입력필요함",

minlength: "최소1자 이상",

maxlength: "최대50자까지",

spaceCheck: "공백있는디요!",

},

pubId: {

required: "입력필요함",

spaceCheck: "공백있는디요!",

},

pubPassword: {

required: "입력필요함",

}

}

});


위에는 내가 기준을 정한 spaceCheck메소드 구현 및 사용법, 아래는 기본적으로 지원하는 메소드


Table of Validation Descriptors

Validation DescriptorUsage
required or
req (필수 입력체크)
The field should not be empty.

Note that this validation if for fields like Textbox and multi-line text box. 
For 'selections' like drop down and radio group, use an appropriate 
validation like 'dontselect' or 'selone_radio'.

maxlen=??? or
maxlength=??? 
(최대글자 정의)
Limits the length of the input.
For example, if the maximum size permitted is 25, give the validation 
descriptor as "maxlen=25″
minlen=??? or
minlength=??? 
(최소글자 정의)
Checks the length of the entered string to the required minimum.
Example "minlen=5″
alphanumeric or
alnum 
(영문자+숫자 만)
The input can contain alphabetic or numeric characters only.
(Note that space or punctuation also are not allowed since those 
characters are not alpha numeric)
alphanumeric_space
alnum_s
(영문자+숫자+공백만)
Allows only alphabetic, numeric and space characters
num
numeric 
(오직 숫자만)
Allow numbers only
alpha
alphabetic 
(오직 영문자만)
Allow only alphabetic characters.
alpha_s
alphabetic_space
(오직 영문자+공백만)
Allows alphabetic and space characters
email
(이메일 형식 확인)
Validates the field to be a proper email address.
(Note, However that the validation can't check whether the email 
address exists or not)
lt=???
lessthan=??? 
(설정값보다 작은지)
Verify the data to be less than the value passed. 
Valid only for numeric fields.
Example: if the value should be less than 1000 give
validation description as "lt=1000″
gt=???
greaterthan=??? 
(설정값보다 큰지)
Verify the data to be greater than the value passed. 
Valid only for numeric fields.
Example: if the value should be greater than 10 give 
validation description as "gt=10″
regexp=??? 
(정규식 설정 비교)
Match the input with a regular expression.
Example: "regexp=^[A-Za-z]{1,20}$" allow up to 
20 alphabetic characters.
dontselect=?? 
(선택 불가 값 설정)
This validation descriptor is valid only for drop down lists. 
The drop down select list boxes usually 
will have one item saying 'Select One' 
(and that item will be selected by default). 
The user should select an option other than this 'Select One' item.
If the value of this default option is '000′, 
the validation description should be "dontselect=000″

Dropdown box with default selected

Drop down list source

dontselectchk=?? 
(선택 불가 체크
기능 동작 여부)
This validation descriptor is only for check boxes. 
The user should not select the given check box. 
Provide the value of the check box instead of ??
For example, dontselectchk=on
shouldselchk=??
(체크박스 필수 선택
기능 동작 여부)
This validation descriptor is only for check boxes. 
The user should select the given check box. 
Provide the value of the check box instead of ??
For example, shouldselchk=on
selone_radio 
(라디오 버튼 필수 
선택 설정)
One of the radio buttons should be selected.
Example:

chktestValidator.addValidation("Options","selone");
Compare two input elements
eqelmnt=??? 
(두개의 값이 일치
여부 확인 
ex:비밀번호)
Compare two input elements. For example: password and confirm password. Replace ??? with the name of the other input element.
Example:

frmvalidator.addValidation("confpassword","eqelmnt=password",
"The confirmed password is not same as password");
neelmnt=??? 
(해당값이 특정 입력
값과 일치하는지 
체크
ex:아이디 비밀번호
값 동일여부 비교)
The value should not be equal to the other input element
Example:

frmvalidator.addValidation("password","neelmnt=username",
"The password should not be same as username");
ltelmnt=??? 
(비교값보다 반드시 
작은지 체크
The input should be less than the other input.
Give the name of the other input instead of ???
leelmnt=??? 
(비교값보다 반드시 
작고 값이 같은지 체크)
The input should be less than or equal to the other input. 
Give the name of the other input instead of ???
gtelmnt=???
(비교값보다 반드시
큰지 체크)
The input should be greater than the other input. 
Give the name of the other input instead of ???
geelmnt=??? 
(비교값보다 반드시
크고 값이 같은지 
체크)
The input should be greater than or equal to the other input. Give the name of the other input instead of ???

앞으로 꼬박 잘 적어야지...한건 많은데 적은게없네




'Java Script & Jquery' 카테고리의 다른 글

page-break-before 속성  (0) 2015.08.05