Validating E-mail Address In Textbox?
I would like to know if there is a simple way to validate an e-mail address? I have seen many ways that appear to use functions but I would like to use something simple because currently my error control is done like this:
If txtEmail.Text = "" Then
ErrorProvider1.SetError(txtEmail, "You must enter your e-mail address.")
Else
ErrorProvider1.SetError(txtEmail, "")
Is there a way to use the same type of syntax but instead of checking if the textbox is empty, check if it a valid e-mail address? I know the regular expressions can be used, but how in this circumstance?
Re: Validating E-mail Address In Textbox?
What characters do you consider invalid?
Re: Validating E-mail Address In Textbox?
I would like to ensure it is a valid e-mail address, such as the regular express checks for.
Re: Validating E-mail Address In Textbox?
Code:
Dim EmailRegEx As New System.Text.RegularExpressions.Regex("\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*")
If EmailRegEx.IsMatch(YourTextBoxHere.Text.Trim) Then
'Is valid
Else
'Not valid
End If
Re: Validating E-mail Address In Textbox?
Thank you! I was having trouble with the expressions for some reason. Every time I tried one, it wasn't the right one because it wasn't ever letting a valid e-mail address pass through. Thank you so much!!!
Re: Validating E-mail Address In Textbox?
No problem, be sure to mark your thread as Resolved.