0

How to make Id card pattern?

I want to make Id card 15 digit pattern in input tag. If numbers exceed limit 15 then it show error if numbers less than 15 then it show error msg

20th Dec 2019, 12:51 PM
Muzamil Qasim
Muzamil Qasim - avatar
2 Answers
+ 1
What value do you use for the 'type' attribute of the <input>? For limiting maximum number of characters allowed you can set 'maxlength' attribute e.g. maxlength = "15" But this only limits the maximum number of characters (prevents entering more than the limit - 15). And this doesn't work if <input> 'type' attribute is number. One way or another, you will have to code the validation to check when the input was less than 15 characters.
20th Dec 2019, 1:39 PM
Ipang
+ 1
var input = document.getElementById(“input”); input.onchange = function(){ if(input.value.length!=15){ errorFunction(); }; };
22nd Dec 2019, 3:25 AM
YoBoi