p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript How-To (http://p2p.wrox.com/forumdisplay.php?f=87)
-   -   Email Validate (http://p2p.wrox.com/showthread.php?t=176)

nskannan2007@yahoo.com June 5th, 2003 07:39 AM

Email Validate
How to validate given email in javascript?


Moharo June 6th, 2003 02:36 AM

that depends on what kind of stuff you want to check in email. good start is detecting "@" and "." characters and also empty space " ". here's how you can do it:

function checkEmail(email) {
     if(email.indexOf("@")!=-1 && email.indexOf(".")!=-1 && email.indexOf(" ")!=-1) {
     alert("Specified email address is invalid");
     return false; }
     else alert("Good email address");

that should do it

the genuine genius

vknowles June 9th, 2003 08:33 AM

If you really want to validate an email address, you might want to use a regular expression. See http://regexlib.com/ for examples of some regular expressions that validate email addresses.

(Old dog learning new tricks...)

U.N.C.L.E. July 3rd, 2003 11:46 PM

Here is my favorite method: (Caution: won't work if scripting is disabled!)


<title>Email Check</title>

<script language="JavaScript"><!--
function Form_Validator(theForm) {
    var regex = /^[\w\.-]+@[\w\.-]+\.[a-zA-Z]{2,3}$/
    if (!regex.test(theForm.Email.value)) {
        alert("Invalid email address.");
        return (false);
    return (true);

  <form method="POST" onsubmit="return Form_Validator(this)" action="javascript:alert('Email is valid')">
    <input name="Email" value="">
    <input type="submit" value="Validate Email">


All times are GMT -4. The time now is 07:32 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.