Results 1 to 6 of 6

Thread: Validating E-mail Address In Textbox?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    136

    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?

  2. #2
    Hyperactive Member The Fire Snake's Avatar
    Join Date
    Sep 2009
    Location
    USA
    Posts
    401

    Re: Validating E-mail Address In Textbox?

    What characters do you consider invalid?
    Remember to click on the scales to the left and rep me if I helped

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    136

    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.

  4. #4
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    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
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    136

    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!!!

  6. #6
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Validating E-mail Address In Textbox?

    No problem, be sure to mark your thread as Resolved.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width