I want to validate National identity card number for my small application.
There are only 9 digits
there is a letter at the end 'x' or 'v' (both capital and simple letters)
3rd digit can not be equal to 4 or 9
How can I validate this using visual studio 2010? can I use regular expression to validate this?
You can do that without REGEX like:
string str = "124456789X";
if ((str.Count(char.IsDigit) == 9) && // only 9 digits
(str.EndsWith("X", StringComparison.OrdinalIgnoreCase)
|| str.EndsWith("V", StringComparison.OrdinalIgnoreCase)) && //a letter at the end 'x' or 'v'
(str[2] != '4' && str[2] != '9')) //3rd digit can not be equal to 4 or 9
{
//Valid
}
else
{
//invalid
}
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