ASP.NET : Regular expression to validate URL.
Regex reg = new Regex(@"@"^(?:ftp|http|https):\/\/(?:[\w\.\-\+]+:{0,1}[\w\.\-\+]*@)?(?:[a-z0-9\-\.]+)(?::[0-9]+)?(?:\/|\/(?:[\w#!:\.\?\+=&%@!\-\/\(\)]+)|\?(?:[\w#!:\.\?\+=&%@!\-\/\(\)]+))?$");
Response.Write(reg.IsMatch(txtwebsite.Text));
string
regURL = @"^(?:ftp|http|https):\/\/(?:[\w\.\-\+]+:{0,1}[\w\.\-\+]*@)?(?:[a-z0-9\-\.]+)(?::[0-9]+)?(?:\/|\/(?:[\w#!:\.\?\+=&%@!\-\/\(\)]+)|\?(?:[\w#!:\.\?\+=&%@!\-\/\(\)]+))?$";
if (Regex.IsMatch(txtwebsite.Text, regURL))
{
// string match with regExpression.
}
Else
{
//String does not validate
}
Comments
Post a Comment