Identity cards number validation

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?

Answers


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
}

Need Your Help

MSVC and FreeGlut Compiler Error

c++ static visual-c++ freeglut

Receiving alot of these messages when compiling which is making compiling a simple program very time consuming.

Parse iOS - How to query PFUser details from another class

ios xcode parse.com xcode6

I am trying to write a Parse query for my iOS social app that will show all users that are following the active user. Here is what I have so far:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.