Friday 9 November 2012

How to Validate the TextBox with Indian Phonenumber Format


 Here we have discuss about the TextBox Validation,for that TextBox takes The Only indian Format Phnumber,for that here is the code for it,and also we have to using one more Namespace is using System.Text.RegularExpressions;
Code for Indian Formate Phone Number:
this code write in the txtPhnumbr_Validating Event

            Regex phNum = new Regex("^\\+[9][1][-][\\d]{10}$");

            Match getmatch = phNum.Match(textBox1.Text);

            if (getmatch.Success)
            {
                errorProvider1.SetError(this.textBox1, "");
            }
            else
            {
                errorProvider1.SetError(this.textBox1, "Phnum Should 10 Digits and Format +91-XXXXXXXXXX");
            }

Here  is the Screen shots for the TextBox Validation with the indian Format Phnumber
figure one shows the error:



Figure two shows the currect Validation:

 Here we use the errorProvider to show the error.

I hope this  code snippet will help you