I try to validate in the text box X and Y letters only for the NIC field. But it's not working. I need to block other letters without X and Y.
Example like this - 881161537V , 881161537X
This is Sri Lankan NIC format.
I appreciate your help. Many thanks!
HTML
<input type="text" name="number">
JS
$("input[name='number']").on('keydown', function(e) {
var key = e.keyCode ? e.keyCode : e.which;
//alert(key);
if (!([8, 9, 13, 27, 46, 110, 190,17, 89, 88].indexOf(key) !== -1 ||
(key == 65 && (e.ctrlKey || e.metaKey)) ||
(key >= 35 && key <= 40) ||
(key >= 48 && key <= 57 && !(e.shiftKey || e.altKey)) ||
(key >= 96 && key <= 105)
)) e.preventDefault();
});
Working Fiddle
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.