php - JavaScript and HTML Regex not working -
i have php page:
<?php if($_server['request_method'] == 'post'){ echo $_post["username"]; echo $_post["password"]; echo $_post["confirm_password"]; echo $_post["email"]; } ?> <!doctype html> <html> <head> <title>wordcat signups</title> <script type="text/javascript" src="signup_validate.js"></script> </head> <body> <form action="" method="post"> username:<br><input type="text" name="username" placeholder="username" onkeyup="check_username();"><span id="check_username"></span><br> password:<br><input type="password" name="password" placeholder="password" onkeyup="check_password();"><span id="check_password"></span><br> confirm password:<br><input type="password" name="confirm_password" placeholder="confirm password" onkeyup="check_passwords();"><span id="check_passwords"></span><br> email:<br><input type="email" name="email" placeholder="email" onkeyup="check_email();"><span id="check_email"></span><br> <input type="submit" name="submit" value="signup"></br> </form> </body> </html>
i have javascript meant check fields:
function check_username(){ var username = document.getelementsbyname("username")[0].value; var pattern = /^[\w[^!\"\#$%&\'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~]]{1,32}$/; if(pattern.test(username)){ document.getelementbyid("check_username").innerhtml = "username valid."; } else { document.getelementbyid("check_username").innerhtml = "username invalid. should contain letters, numbers, , underscores, have maximum of 32 characters."; } } function check_password(){ var password = document.getelementsbyname("password")[0].value; var pattern = /^(?=.*[a-z])(?=.*[a-z])(?=.*\d)([a-za-z0-9!\"\#$%&\'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~]{6,})$/; if(pattern.test(password)){ document.getelementbyid("check_password").innerhtml = "password valid."; } else { document.getelementbyid("check_password").innerhtml = "password invalid. should have @ least 6 characters, , @ least 1 number, uppercase, , lowercase character."; } } function check_passwords(){ var password = document.getelementsbyname("password")[0].value; var confirm_password = document.getelementsbyname("confirm_password")[0].value; if(password == confirm_password){ document.getelementbyid("check_passwords").innerhtml = "passwords match"; } else { document.getelementbyid("check_passwords").innerhtml = "passwords not match."; } }
however, javascript, username , confirm password tests working, password regex not. when key in valid passwords. regex can found here link , correct tests. when use browser regex fails valid passwords online!
i don't see reason use single regex complex condition yours (other showing off regex-fu)...
if( password.length >= 6 && // @ least 6 characters /[0-9]/.test(password) && // @ least 1 number /[a-z]/.test(password) && // @ least 1 lowercase character /[a-z]/.test(password) // @ least 1 lowercase character ) { // yay :) }
Comments
Post a Comment