Textbox Contains Character

Results 1 to 2 of 2

Thread: Textbox Contains Character

  1. #1
    Gord Guest

    Default Textbox Contains Character

    I&#039m working on a small security form and want to make sure that people enter a valid email address (or atleast valid format). <BR><BR>I want to check if txtEmail.value contains an @ and . (period) character, like a valid email address should. I know there is a way to do this because I&#039ve encountered it on many sites.<BR><BR>I just need to know what the code is to check if the value contains the characters.<BR><BR>Any help is greatly appreciated,<BR><BR>Gord<BR>gabi@bconnex.net

  2. #2
    Join Date
    Dec 1969
    Posts
    29

    Default RE: Textbox Contains Character

    There is a probably a better way using the javascript and vbscript regular expression routines, but if all you want to do is check for those valid characters, you can do the following and not worry if your viewers have scripting enabled:<BR><BR>&#060;%<BR>Dim email, validEmail<BR>email = Text1.Text<BR>validEmail = True<BR><BR>&#039Get the positions of the characters required<BR>Dim atSymbol, period<BR>atSymbol = InStr(email, "@")<BR>period = InStr(email, ".")<BR><BR>&#039make sure the @ symbol is at least the second character<BR>If Not atSymbol &#062; 1 Then<BR> validEmail = False<BR>End If<BR><BR>&#039make sure there are some characters between the @ and the period<BR>If Not (period - atSymbol) &#062; 1 Then<BR> validEmail = False<BR>End If<BR><BR>&#039make sure there are some characters after the period<BR>If Not Len(email) - period &#062; 0 Then<BR> validEmail = False<BR>End If<BR>%&#062;<BR><BR>and now the variable validEmail will contain "true" or "false"<BR>depending if it is valid<BR>

Posting Permissions

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