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