javascript - Check if value matches mask -
i have input has mask of date __/__/____
. stored in variable. there way detect if matches mask properly?
the event binded on blur, returning values 22/12/___
.
is there way detect if fits scheme integers , slash or doesn't?
$('#btn').click(function() { value = $('#my-input').val() // should in format 99/99/9999 , not 12/12/12__ // here need check if in right format. if (checkformat(value)) { } }
you can use regex validate this.
var regex_check = /^\d{2}\/\d{2}\/\d{4}$/ ;
//edit - vanilla javascript
function foo(date) { var regex_pattern = /^\d{2}\/\d{2}\/\d{4}$/ ; var check = new regexp(regex_pattern); var res = check.test(date); // return true or false return res; }
Comments
Post a Comment