Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for e-mail in a form

Status
Not open for further replies.

teky

Programmer
Mar 24, 2000
55
US
I have a form requesting user information.<br>I would like to check if the user has entered a valid e-mail address.<br>Is there any way I can do that.<br>Help me with this.<br>Thanking you in advance.<br>Vijay Donthi. <p> <br><a href=mailto: > </a><br><a href= > </a><br>
 
well using javascript u can check..for the '@' and the '.com'..but there is no gurantee that user entered email id is valid..:))<br><br>regards <br>Vinod
 
do not check for .com... the user may be using a .net email address.. actually without getting really complicated, be sure it is not blank, use indexOf to test for an '@' and '.'s.
 
This is a script which I haven't finished but which shows one approach to this problem. It checks for the format &quot;<A HREF="mailto:text@text.text">text@text.text</A>&quot; and also for bad characters. You will have to double check as to what characters are valid in email addresses because I can't remember. The algorithm is:<br>check for the existence of a single &quot;@&quot; then split string there and check either substring for non-zero length. Repeat process for second substring but splitting now at &quot;.&quot; Finally, check for allowed characters. You will have to check what the allowed chars are because I'm not sure. Also I don't check for certain very unlikely things like consecutive periods and probably other stuff but you get the idea. Also you could do all this with a regular expression object but I'm working with an earlier version of ASP which is why I'm doing all this old-fashioned stuff.<br><br><br><br>'-------validate email address<br>addr = request.FORM(&quot;emailaddress&quot;) '---user inputted email<br>addrBOOL = true<br>if instr(addr,&quot;@&quot;) = 0 then <br>      addrBOOL = false<br>else<br>      splitAT = split(addr,&quot;@&quot;)<br>      if splitAT(0) = &quot;&quot; OR splitAT(1) = &quot;&quot; OR NOT instr(splitAT(1),&quot;@&quot;) = 0 OR instr(splitAT(1),&quot;.&quot;) = 0 then <br>            addrBOOL = false<br>      else<br>            splitPERIOD = split(splitAT(1),&quot;.&quot;)<br>            if splitPERIOD(0) = &quot;&quot; OR splitPERIOD(1) = &quot;&quot; then<br>                  addrBOOL = false<br>            end if<br>      end if<br>end if<br><br>for i = 1 to len(addr)<br>      x = asc(mid(addr,i,1))<br>            if x&lt;45 OR (x&gt;46 AND x&lt;48) OR (x&gt;57 AND x&lt;64) OR (x&gt;90 AND x&lt;95) OR x=96 OR x&gt;122 then<br>            addrBOOL = false<br>      end if<br>next<br><br>'------if addrBOOL is true at this point, email string has passed all of the above tests so you can write:<br><br>if addrBOOL then<br>      
Code:
<br>else<br>      response.write(&quot;Your email is incorrectly formatted...&quot;)<br>end if<br><br><br><br>will duty<br><A HREF="mailto:wduty@radicalfringe.com">wduty@radicalfringe.com</A>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top