javascript - Check input for 4 numbers and 2 letters with jQuery -
i have text <input>
maxlength="6"
want check if first 4 characters numbers , last 2 letters.
i have code:
$("input[id='post']").keyup(function count() { //what goes here? });
but don't know how go on further.
you can use regex this
$("input[id='post']").keyup(function count() { var input = this.value; var regex = new regexp(/^[0-9]{4}[a-z]{2}$/i); console.log(regex.test(input)); });
[0-9]{4}
- checks 4 digits between 0-9.
[a-z]{2}
- checks 2 letters between a-z. i
flag @ end makes check case-insensitive.
Comments
Post a Comment