Validate Email. RegEx. Need Help.

  • Thread starter Thread starter Shapper
  • Start date Start date
S

Shapper

Hello,

I have the variable "emailAddress" in my Code File (myPage.aspx.vb).

I need to check, in Page_Load, if the email address saved in my variable
is valid. I found many examples of how to use ASP.NET validation in aspx
code but I can't find examples on how to use RegEx in my VB.Net code.

Can someone help me out?

Thank You,
Miguel
 
Shapper said:
Hello,

I have the variable "emailAddress" in my Code File (myPage.aspx.vb).

I need to check, in Page_Load, if the email address saved in my variable
is valid. I found many examples of how to use ASP.NET validation in aspx
code but I can't find examples on how to use RegEx in my VB.Net code.

Can someone help me out?

Thank You,
Miguel
Try something like this...

Dim x As String = TextBox1.Text

Const pattern As String = "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"

Dim theRegEx As New System.Text.RegularExpressions.Regex(pattern,
System.Text.RegularExpressions.RegexOptions.Compiled)

If theRegEx.IsMatch(x) Then

Label1.Text = "Valid email"

Else

Label1.Text = "Bad email address"

End If

Watch out for line wrap in the above.
 
Thanks Peter,

It was exactly that what I was looking for.
I didn't know how to use the Regular Expressions.
Now I know.

Thanks Once Again,
Miguel

Hello,

I have the variable "emailAddress" in my Code File (myPage.aspx.vb).

I need to check, in Page_Load, if the email address saved in my variable
is valid. I found many examples of how to use ASP.NET validation in aspx
code but I can't find examples on how to use RegEx in my VB.Net code.

Can someone help me out?

Thank You,
Miguel

Try something like this...

Dim x As String = TextBox1.Text

Const pattern As String = "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"

Dim theRegEx As New System.Text.RegularExpressions.Regex(pattern,
System.Text.RegularExpressions.RegexOptions.Compiled)

If theRegEx.IsMatch(x) Then

Label1.Text = "Valid email"

Else

Label1.Text = "Bad email address"

End If

Watch out for line wrap in the above.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top