Friday, July 3, 2009

C# Mobile Number Validation

The following c# function is used to validate the Mobile Number of US.
It must be atleast 10 characters but not greater than 12 characters
It may contain characters ( and -.
It can contain Space.
It must not containt alphabets or other characters
The opening ( must be having Closing ).
will return true if the mobile number is valid otherwise return false.

private bool ValidateMobileNumber(String MobileNum)
{
bool RtnVal = true;

//Length must be >= 10 but <= 12 if ((MobileNum.Length <> 12))
{
RtnVal = false;
}
else
{
int Pos;
int NumChars;

NumChars = MobileNum.Length;


//Check For Characters
for (Pos = 0; Pos < rtnval =" false;" rtnval =" false;">



Example

{

if (!ValidateMobileNumber(txtMobile.Text))
{
lblError.Text = "Error in Mobile Number";
txtMobile.Focus;
}


}

No comments:

Post a Comment