I need regex to validate an Pakistani National ID Card (NIC) number which contains Digits and Dashes in format given below
12345-1234567-1
Please help..
you can use standard javaScript to test the Regex expression:
var idToTest = '12345-1234567-1',
myRegExp = new RegExp(/\d{5}-\d{7}-\d/);
if(myRegExp.test(idToTest)) {
//if true
}
else {
//if false
}
Try this:
var cnic_no = '12345-1234567-9',
var cnic_no_regex = /^[0-9+]{5}-[0-9+]{7}-[0-9]{1}$/;
if(cnic_no_regex.test(cnic_no))
{
alert('Right');
}
else
{
alert('Wrong');
}
JsFiddle: https://jsfiddle.net/k81w2x77/1/
JsFiddle: https://jsfiddle.net/fokq2woq/10/
This will validate it. (As long as the format is exactly as you state)
\d{5}-\d{7}-\d
this should be like that
myRegExp = new RegExp(/\d{5}-\d{7}-\d{1}$/);
You can use this regex to validate CNIC
^[0-9+]{5}-[0-9+]{7}-[0-9]{1}$
to see how to use it in jquery function, see this example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With