function PassportValidate(s, e) {
var option = rbIdentityVerification.GetValue().toString(); //gets the selected option which is NIC selected by default. devexpress radiobuttonlist
var text = e.value.toString(); //gets the value from the textbox
if (option == "NIC") {
var pattern2 = RegExp("^\d{9}(X|V)$");
if (!pattern2.test(text)) {
e.isValid = false;
e.errorText = "Passport number invalid.(Max 9 numbers)"; //Error message that is to be shown
}
}
}
function PassportValidate(s, e) {
var option = rbIdentityVerification.GetValue().toString(); //gets the selected option which is NIC selected by default. devexpress radiobuttonlist
var text = e.value.toString(); //gets the value from the textbox
if (option == "NIC") {
var pattern2 = RegExp("^\d{9}(X|V)$");
if (!pattern2.test(text)) {
e.isValid = false;
e.errorText = "Passport number invalid.(Max 9 numbers)"; //Error message that is to be shown
}
}
}
Regular expression to validate National Identity Card number which has 9 digits with final digit being X or V. the code always return invalid, so even a correct NIC is entered still returns as invalid
Share Improve this question edited Dec 5, 2015 at 9:12 Bartłomiej Semańczyk 62k52 gold badges250 silver badges401 bronze badges asked Dec 3, 2015 at 8:24 Lourdes AdheeshaLourdes Adheesha 311 silver badge2 bronze badges 1- 1 please ignore the error text... – Lourdes Adheesha Commented Dec 3, 2015 at 8:25
3 Answers
Reset to default 2Though \d
is modern regex shorthand for [0-9]
, I prefer to use latter.
This regex work fine ^([0-9]{9})(X|V)$
.
Here is the working jsfiddle.
Try using This (Sri Lanka NIC new and old formats). This will accept all the numbers with V or X (Upper or lower).
/^([0-9]{9})(X|V)$|^([0-9]{11})/gis
I think this may will help you
^\d{9}[V|v|X|x]$