javascript - Check if user input has certain characters -
hi i'm making "secure password" project school , need check if user input has "!@$%&#" , if have tell them password secure.
this project school im stuck doing :(
var password = document.getelementbyid('password'); var emsg = document.getelementbyid('feedback'); var minlength = 6; function checkpass() { if (password.value.length < minlength) { emsg.innerhtml = 'password must have' + minlength + 'characters or more'; } else { emsg.innerhtml = ''; } }
<html> <head> <title> password secured </title> <link rel="stylesheet" href="style.css"> </head> <body> <h1 class="logo"> logo</h1> <br/> <br/> <p class="input">please type password: <br/> <input type="text" id="password" /> <div id="feedback"></div> </p> <br/> <p class="answer"></p> <br/> <br/> <p class="tips"> <br/>tips tips tips </p> </body> </html>
you can test string using regular expression:
function isvalid(str){ return !/[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g.test(str); }
possible duplicate of javascript code check special characters
Comments
Post a Comment