Sunday, November 15, 2015

C# Validation Codes

Email Validation Code

private void button1_Click(object sender, EventArgs e)
        {
            String ID = txtID.Text;

            if ((ID.Count(char.IsDigit) == 9) && (ID.EndsWith("X") || ID.EndsWith("V")) && (ID[2] != '4' && ID[2] != '9'))
            {
                MessageBox.Show("Valid ID");
            }
            else
            {
                MessageBox.Show("Invalid ID");
            }
      }

NIC Validation Code

private void button1_Click(object sender, EventArgs e)
{
string pattern = null;pattern = "^([0-9a-zA-Z]([-\\.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$";

            if (Regex.IsMatch(txtEmail.Text, pattern))
            {
                MessageBox.Show("Valid Email address ");
            }
            else
            {
                MessageBox.Show("Not a valid Email address ");
            }
}

No comments: