Click to See Complete Forum and Search --> : javascript


srimca
01-23-2003, 12:29 PM
hi freinds...

pls tell me an efficeient way for email validation in javascript

sciguyryan
08-11-2003, 04:58 AM
hi,


There is only one way to validate an E-mail adress and that is to check if there is an "@" sign in it as all valid E-mail addresses must contain.


the script should go something like this:

<HTML>
<HEAD><TITLE> VALIDATION </TITLE>
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
function evalform (address)
{
crucial = address.indexOf ("@");
if (crucial == -1)
{
window.alert('Your E-mail adress is not valid.Please enter a valid one') ;
return false
}
else
{
return true
};
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<FORM OnSubmit="elalform(this.email.value)">
<INPUT NAME="email" TYPE="TEXT" ROWS="1" SIZE="20">Enter your E-mail address here.
<INPUT NAME="submit" TYPE="submit">
<INPUT NAME="reset" TYPE="reset">
</FORM>
</BODY>
</HTML>

Charles
08-11-2003, 05:18 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<script type="text/javascript">
<!--

String.prototype.isEmailAddress = function () {return this.match(/^[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)*\@[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)+$/)}

// -->
</script>
<form action="">
<div>
<input type="text" onchange="if (!this.value.isEmailAddress()) {alert ('That would not appear to be a valid email address.'); this.value=''; this.focus()}" />
<button type="submit">Submit</button>
</div>
</form>