VB.NET Regular Expression to Validate Url
Imports System.Text.RegularExpressions
Function IsValid_URL_Address(ByVal sURLAdd As String)
Return Regex.IsMatch(sURLAdd, "(https?ftp):\/\/([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})(:\d{1,4})?([-\w\/#~:.?+=&%@~]*)/")
End Function
The above will check for URL like http://www.dotnetdud.com etc
See Also
Extract Ref Links From WebPage using VB.Net Regular Expressions
Remove HTML Tags from String using .NET Regular Expressions
VB.NET Regular Expression to Check URL
VB.NET Regular Expression to Check Email Addresses
VB.NET Regular Expression to Check MAC Address
Regular Expression to Check Zip Code
Validate eMail Addresses using VB.NET Function
Regular Expressions in Dot Net (.NET)
There's a mistake with the ) and (.
ReplyDeleteHi Sebastian. Can you post the new regex expression
ReplyDeleteof course, this doesn't even work!
ReplyDeleteHi Can you check if the following works for you:
ReplyDeleteprivate bool IsValid_URL_Address(string sURLAdd)
{
MessageBox.Show(Regex.Match(sURLAdd, @"(https?|ftp):\/\/([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9}(:\d{1,4})?([-\w\/#~:.?+=&%@~]*)?").ToString());
return Regex.IsMatch(sURLAdd, @"(https?|ftp):\/\/([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9}(:\d{1,4})?([-\w\/#~:.?+=&%@~]*)?");
}
The following example will allow you to Input valid website address only, chk this:
ReplyDeletehttp://www.authorcode.com/regular-expression-for-validating-format-of-website-address-in-vb-net/