Sections
     
     
WWWCoder.com Resource Directory

Code Snip: Using Regular Expressions for Validation
9/27/2005 3:50:15 PM

Regular expressions are great for evaluating string values and ensuring that what you get from the user input is what you want. The following three methods are great for checking input for Internet applications.

Regular expressions are great for evaluating string values and ensuring that what you get from the user input is what you want. The following three methods are great for checking input for Internet applications.

The first function is for validating an email address. It accepts the email address as a string input, and returns a boolean value informing the application if it is a valid email.

Function IsValidEmail(ByVal email As String) As Boolean
    Return System.Text.RegularExpressions.Regex.IsMatch(email, _
    "^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$")
End Function

The second function is for validating an URL. Again, this function accepts the URL as a string input, and returns a boolean value informing the application if it is a valid Internet address.

Function IsValidUrl(ByVal url As String) As Boolean
    Return System.Text.RegularExpressions.Regex.IsMatch(url, _
    "(http|ftp|https)://([\w-]+\.)+(/[\w- ./?%&=]*)?")
End Function


Page Options:
format for printing  Format for Printer
email article  Email Page
add to your favorites   Add to Favorites
How would you rate the quality of this content?
Poor - - Excellent
Comments?
Overall Rating:
Comments Left:
Left on 9/11/2007 1:56:58 AM by Anonymous
Comments: Quality of this Content is Excellent.
Left on 6/28/2007 11:00:06 AM by Anonymous
Comments: Even the url one didnt work so well.  Try this page, they have more robust reg ex strings:  http://regexlib.com/Search.aspx?k=url
No ratings available.
Left on 11/27/2006 12:41:45 AM by Anonymous
Comments:
Left on 3/9/2006 5:02:36 PM by Anonymous
Comments: the regular expression for IsValidEmail does not work.
No ratings available.
     
     

 

     
     

 


 


Digg This
 


DotNetNuke Platinum Benefactor

     
     

Other family network sites: santry.com - katieandkarleigh.com

Powered by 

 

     
Copyright 20010 - Santry Technology Solutions, Box 172, Girard, PA 16417, (814) 774-0970
Privacy Statement | Terms Of Use