자바스크립트 유효성검사 API

DOM 메소드 제약조건 유효성검사

Property Description
checkValidity() Returns true if an input element contains valid data.
setCustomValidity() Sets the validationMessage property of an input element.

입력 필드에 유효하지 않은 데이터가 포함되면, 메시지를 표시합니다:

The checkValidity() Method


DOM 속성 제약조건 유효성검사

Property Description
validity Contains boolean properties related to the validity of an input element.
validationMessage Contains the message a browser will display when the validity is false.
willValidate Indicates if an input element will be validated.


유효성검사 속성

입력 요소의 유효성검사 속성(validity property)은 데이터의 유효성검사와 관련된 여러 속성을 포함합니다:

Property Description
customError Set to true, if a custom validity message is set.
patternMismatch Set to true, if an element’s value does not match its pattern attribute.
rangeOverflow Set to true, if an element’s value is greater than its max attribute.
rangeUnderflow Set to true, if an element’s value is less than its min attribute.
stepMismatch Set to true, if an element’s value is invalid per its step attribute.
tooLong Set to true, if an element’s value exceeds its maxLength attribute.
typeMismatch Set to true, if an element’s value is invalid per its type attribute.
valueMissing Set to true, if an element (with a required attribute) has no value.
valid Set to true, if an element’s value is valid.

Examples

입력한 숫자가 100을 초과하면 (the input’s max attribute), 메시지를 표시합니다:

The rangeOverflow Property

입력한 숫자가 100 미만이면 (the input’s min attribute), 메시지를 표시합니다:

The rangeUnderflow Property

출처: JavaScript Validation API

카테고리

답글 남기기