javascript - JS send message on correct input -
i have submit form users using register:
<form method="post" action="<?php echo $_server["php_self"]; ?>" name="form" onsubmit="return validate(this);"> <div class="form-group"> <input type="text" id="name" name="name" class="inputs" /><br /> <input type="text" id="email" name="email" class="inputs" /><br /> <input type="password" id="password" name="password" class="inputs" /> </div> <input type="submit" class="btn1" name="register" value="register" /> </form>
the js code checking if data entered correctly. if user enters incorrect date js code showing message. want show message when data entered correctly. tried add row if (errors.length < 0)
didn't work. js code sends me message "correct input" , message "dont use symbols...\n".
how can make working?
here js code:
<script type="text/javascript"> var ck_name = /[a-za-z0-9. ]{3,25}$/; var ck_email = /^[a-za-z0-9._-]+@[a-za-z0-9.-]+\.[a-za-z]{2,4}$/; var ck_password = /^[a-za-z0-9!@#$%^&*()_]{6,20}$/; function validate(form) { var name = form.name.value; var email = form.email.value; var password = form.password.value; var errors = []; if (!ck_name.test(name)) { errors[errors.length] = "name error! ."; } if (!ck_email.test(email)) { errors[errors.length] = "email error! ."; } if (!ck_password.test(password)) { errors[errors.length] = "password error!"; } if (errors.length > 0) { reporterrors(errors); return false; } return true; } function reporterrors(errors) { var msg = "dont use symbols...\n"; (var = 0; i<errors.length; i++) { var numerror = + 1; msg += "\n" + numerror + ". " + errors[i]; } alert(msg); } </script>
errors.length never won't minor of 0. must use equal (==). works! :-)
update
if (errors.length == 0) { alert('correct input'); }
that before return true statement , after if (errors.length > 0).
Comments
Post a Comment