Validate and Convert to mobile Number

Just call this function and enjoy.
It will automatically remove invalid mobile number and provide valid mobile number.

private string convert_to_number(string No)
    {
        string mobileno = "";
        //remove special characters
        foreach (char ch in No)
        {
            if (ch != ' ' && ch != '+' && ch != '-')
            {
                mobileno = mobileno + ch.ToString();
            }
        }
        //convert to 10 digit
        if (mobileno.Length > 10)
        {
            mobileno = mobileno.Substring(mobileno.Length - 10, 10);
        }
        return (mobileno);
    }
Ebook Download
View all
Learn
View all