Validate Mobile and Aadhar number using Regular Expression in Windows Application

Last Reply on Jul 03, 2018 03:19 AM By dharmendr

Posted on Jul 03, 2018 01:31 AM

I want to do validation for Mobile Number and aadhar number (12 or 16 digit) in windows form.

How to do it please give me refernce links

Thanks

Posted on Jul 03, 2018 03:19 AM

Hi ashishk,

Check this example. Now please take its reference and correct your code.

Form Design

Code

C#

private void btnMobile_Click(object sender, EventArgs e)
{
    if (!System.Text.RegularExpressions.Regex.IsMatch(txtMobile.Text.Trim(), "^[0-9]{10}$"))
    {
        MessageBox.Show("Enter 10 Digit mobile number");
    }
}

private void btnAadhar_Click(object sender, EventArgs e)
{
    if (!System.Text.RegularExpressions.Regex.IsMatch(txtAadhar.Text.Trim(), @"^(\d{12}|\d{16})$"))
    {
        MessageBox.Show("Enter 12 or 16 Digit Aadhar number");
    }
}

Screenshot