Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery NIC validate

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..

like image 650
Baig Avatar asked Mar 19 '13 12:03

Baig


5 Answers

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
}
like image 184
Wim Ombelets Avatar answered Nov 16 '22 14:11

Wim Ombelets


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/

like image 5
Ali Avatar answered Nov 16 '22 15:11

Ali


This will validate it. (As long as the format is exactly as you state)

\d{5}-\d{7}-\d

like image 2
Richard Brown Avatar answered Nov 16 '22 14:11

Richard Brown


this should be like that

myRegExp = new RegExp(/\d{5}-\d{7}-\d{1}$/);
like image 2
syed farooq Avatar answered Nov 16 '22 15:11

syed farooq


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.

like image 1
CodingSolutions Avatar answered Nov 16 '22 16:11

CodingSolutions