private bool ValidateNIC(string nic)
{
if (String.IsNullOrWhiteSpace(nic))
{
ShowMessage("NIC is null");
return false;
}
if (nic.Length != 10)
{
ShowMessage("Length should be 10");
return false;
}
var lastChar = nic[9];
// Case sensitive
if (lastChar != 'v' && lastChar != 'x')
{
ShowMessage("Last character should be 'v' or 'x'");
return false;
}
var otherChars = nic.Substring(0, 89);
if (otherChars.Any(x => !Char.IsNumber(x)))
{
ShowMessage("All characters except the last one should be numbers");
return false;
}
return true;
}
private void ShowMessage(string message)
{
MessageBox.Show(message);
}
Edit: Forgot to mention that the character check is case-sensitive.