/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Form email address validation

Trying to ensure an email address is in the correct format, but it is showing the alert message regardless what is typed in.
How do you check if a field is NOT in the correct format?? Currently im using the code below:

[CODE]

function validateOnSubmit()
{

var email = “”;
var theEmail = document.example.email.value;
var atLoc = theEmail.indexOf(“@”,1);
var dotLoc = theEmail.indexOf(“.”,atLoc+2);
var len = theEmail.length;

if (document.example.email.value==””)
{
alert(“Please enter your email address”)
document.example.email.focus();
document.example.email.select();
return false;
}

if (document.example.email != (atLoc > 1 && dotLoc > 1 && len > dotLoc+2))
{
alert(“Please check your email address”)
return false;
}

return true;

}

[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERJun 01.2007 — Two questions:

1. What kind of error(s),if any, are you getting in the JS console?

2. Do you have your form and elements named 'example' and 'email'?
Copy linkTweet thisAlerts:
@samwisegamgee16authorJun 01.2007 — Problem solved

[CODE]

if (!(atLoc > 1 && dotLoc > 1 && len > dotLoc+2))

[/CODE]


Thanks anyways ?
×

Success!

Help @samwisegamgee16 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...