Validate Mobile and Aadhar number using Regular Expression in Windows Application

Last Reply 2 months ago By dharmendr

Posted 2 months ago

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 2 months ago

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