/    Sign up×
Community /Pin to ProfileBookmark

Email verification

I’ve been writing actionscript for a few years now, but am fairly new to JavaScript
I wrote an email verification form last nite and it seems to be working fairly well locally (unless i hit enter…it only works if i click on submit) But is giving other people all kind of problems.

here is the code
<html><head><title>E.C.</title></head>

<form name=”email” onSubmit=”checkEmail(); return false;”>
<input type=”text” name=”email1″ value=”Enter Email Here” onFocus=”window.document.email.email1.value=’ ‘;” onBlur=”window.document.email.email1.value=’Enter Email Here’;”>
<br>
<input type=submit value=” Submit “>
<input type=reset value=” Reset Form “>

</form>

<script language = “javascript”>

function checkEmail()
{

var alertMessage=”You’ve entered an invalid e-mail address”;
var alertMessageGood= “Thank You!”;

var lowerCase = window.document.email.email1.value.toLowerCase();

var checkAt = lowerCase.indexOf(“@”);

var checkPer = lowerCase.substring(checkAt + 1, lowerCase.length);

var checkPer2 = checkPer.indexOf(“.”);

if(window.document.email.email1.value.length < 8){alert(alertMessage + “(length)”);}
else if(checkAt == -1) {alert(alertMessage + “(@sign)”);}
else if (checkPer2 == -1){alert(alertMessage + “(Period)”);}
else if(checkPer.charAt(length – 1) == “.”){alert(alertMessage + “(Period)”);}
else{alert(alertMessageGood);}

}

</script>

</html>

And [URL=http://polturk-pad.dyndns.org/java/java25.html]here[/URL] is the link to test it at
If anyone could give me some help with this id be appreciative.
Thanks,
Eric

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@ExuroAug 01.2003 — Just after I learned to use Regular Expressions I wrote an email validation script. Here it is if you want to play around with it:

[FONT=courier new]

<html>

<head>

<script language="JavaScript" type="text/javascript">

<!--

function validate() {

var str = document.form1.email.value;

var isValid = /^[w]+[-w_]+@([w]+[-w._]+.[a-zA-Z]{2,4}|d{1,3}.d{1,3}.d{1,3}.d{1,3})$/.test(str);

if (isValid) {

document.getElementById('disp').innerHTML = "<b>"+str+"</b> is a valid email address!"

}

else {

document.getElementById('disp').innerHTML = "<b>"+str+"</b> is <i>not</i> a valid email address!"

}

}

//-->

</script>

</head>

<body>

<form name="form1" action="#" method="get" onsubmit="validate();return false;">

Email: <input type="text" name="email" /><br /><br />

<input type="Submit" value="Submit" />

</form>

<div id="disp"></div>

</body>

</html>

[/FONT]

I'm not sure if it works 100% correctly, but from what I tried it seemed to work pretty well... RexExps seem to be more a much more effective way of doing tasks such as validating email addresses than using a bunch of indexOf() statements. If you want to read up on regular expressions you can do so here:

http://www.webreference.com/js/column5/index.html
Copy linkTweet thisAlerts:
@CharlesAug 01.2003 — [font=monospace]<!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>

<form action="">

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

<div>

<input type="text" onchange="if (!this.value.isEmailAddress()) {alert ('That would not appear to be a valid email address.'); this.value=''; this.focus()}" onfocus="this.value=''; this.onfocus = function(){}" value="Email address">

<input type="submit">

</div>

</form>[/font]
×

Success!

Help @pwned spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...