Wednesday, January 24, 2007

Using a Regular Expression in the Code Behind page

I searched google for something like this but didn't find any...
So am posting the one which I made here..

Function IsValidEmail(ByVal strEmail As String) As Boolean
Dim RegExp As New Regex("\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*")
Return RegExp.IsMatch(strEmail)
End Function

Now on the respective event call the function like this..

Dim boolValid As Boolean
boolValid = IsValidEmail("rajesh@nurture3.com")
Response.Write(boolValid)

Cheers
Rajesh Sivaraman.