URL validation in C# window application

Samirbhogayta
Posted by Samirbhogayta under ASP.NET category on | Points: 40 | Views : 2051
private void TextBox1_Validating(object sender, CancelEventArgs e)
{
System.Text.RegularExpressions.Regex rURL = new System.Text.RegularExpressions.Regex(
@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
if (txtURL.Text.Length > 0)
{
if (!rURL.IsMatch(txtEmail.Text))
{
MessageBox.Show("Please provide valid URL", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtURL.SelectAll();
}
}
}

Comments or Responses

Login to post response