jQuery-Form-Validator icon indicating copy to clipboard operation
jQuery-Form-Validator copied to clipboard

Age(18 years) checking with dynamic message!

Open rakibdevs opened this issue 6 years ago • 0 comments
trafficstars

$.formUtils.addValidator({
  name : 'adultcheck',
  validatorFunction : function(value) {
    var birthDate = new Date(value);
    var difdt = new Date(new Date() - birthDate);
    var age=difdt.toISOString().slice(0, 4) - 1970;
    if (age >= 18) {
        return true;
    }
    else if(age<0){
    	this.errorMessage="Not yet born!";
    	return false;
    }
    else{
    	this.errorMessage="Your age is under 18!";
	    return false;
    }	    
  },
});
$.validate();

rakibdevs avatar Jul 21 '19 04:07 rakibdevs