카테고리 없음

[자바 스크립트] moment.js로 입력 연령 확인

행복을전해요 2021. 1. 29. 01:32
<input type="text" name="SocialSecurityNumber" onblur="return validate(this.value);" />

개인적으로 jquery 유효성 검사기를 사용하고이 방법을 만들었습니다.

$.validator.addMethod("minage", function(value,element,argument){
  var age = moment(value);
    var now = moment();
      return this.optional(element) || now.diff(age,'years') >= argument;
      }, $.format("Applicant must be at least {0} years old.")); 
      


출처
https://stackoverflow.com/questions/22039799