In the below code the first and last regex always gives "enter again" as output while the second one always gives "welcome" as output.
where is the error?I'm passing values from
code:<form action="homepage.php" name="myForm" method="post">
<input type="submit" name="s" value="GO" onclick="return validateForm()">
and i want to redirect to homepage.php after validation.
<script type="text/javascript">
function validateForm() {
var x = document.forms["myForm"]["user"].value;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= x.length) {
alert("Not a valid e-mail address");
return false;
}
var y = document.forms["myForm"].elements["pass"].value;
//var passw=/^.*(?=.{8,})(?=.*[a-zA-Z])(?=.*\d)(?=.*[!#$%&? "]).*$/;
var passw = /^((?=.*[a-zA-Z])(?=.*\d)(?=.*[#@%$]).{5,10})$/;
alert(x);
alert(y);
//var passw=/^[A-Za-z0-9]\w{5,10}$/;
if (y.match(passw)) {
alert('Welcome')
return true;
} else {
alert('enter again')
return true;
exit();
}
}
</script>