/    Sign up×
Community /Pin to ProfileBookmark

basic question on code for Basic validation

Hi im trying to work out email and password validation using javascript. Has to be javascript as it is a college assignment, and i know it is basic and flawed with ‘what ifs’ but the guidelines only state validation so…. here is my code anyway.

<script type=”text/javascript”>
function validateForm()
{
var x=document.forms[“myForm”][“email”].value
var y=document.forms[“myForm”][“password”].value

var atpos=x.indexOf(“@”);
var dotpos=x.lastIndexOf(“.”);
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length ||”y”!=123)

{
alert(“Not a valid e-mail address”);
return false;
}

{alert”not a valid password};
return false
}
</script>

||”y”!=123 – without this bit the email verification works ‘fine’ – fine enough for this project anyway – i think this bit of code is incorrect or done wrong. Any suggestions on what to add or where to make it possible for the password to be 123 and anything else would be incorrect? Im sure it will be smackingly obvious to someone, but ive tried a few variations without success.

Many thanks

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@FangApr 18.2011 — y is a variable -> y

An input value is a string -> "123"
[CODE]y != "123"[/CODE]
×

Success!

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

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

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