Please i need to validate the password field this way, must contain atleast one uppercase letter, lowercase, number. please i need this to be in someway this format not in jquery cause i have other if statement for other fields. Not a JS Expert tho. Thanks if(!/^[a-zA-Z]*$/g.test(document.regForm.password.value)) { alert("Password must contain an Alphabet(Upper ), Number,"); document.regForm.lastname.focus(); return false; }
What would happen if someone used non-English letters? Check out this page: https://stackoverflow.com/questions...-uppercase-letter-one-lowercase-letter-and-on Stackoverflow will have numerous solutions, just pick the one you like.
if(!firstpassword.match((/^(?=.\d)(?=.[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$/))) { alert("Password must be Alphanumeric"); return false; } Above is the code i want. But It print "Password must be alphanumeric" even if it has combination of both
^(?=.\d)(?=.[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$ How can I limit the above expression to just aphanumeric and regardless of case?
if(firstpassword.match(/[^a-z0-9]+/i)) { ("password must be alphanumeric"); } Please and also the above code does not work
Shouldn't be like this? if(/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d).*$/.test(document.regForm.password.value)) { alert("Password must contain an Alphabet(Upper ), Number,"); document.regForm.lastname.focus(); return false; }
It dosen't work Here is the whole code -must have atleast one number <html> <script> // PASSWORD // PASSWORD function validateForm() { var firstpassword = document.regForm.password.value; firstpassword = firstpassword.trim(); var secondpassword = document.regForm.password2.value; secondpassword = secondpassword.trim(); if(firstpassword==null || firstpassword==""){ alert("Please enter Password"); return false; } if(/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d).*$/.test(document.regForm.password.value)) { alert("Password must contain an Alphabet"); document.regForm.password.focus(); return false; } //minimum password length validation if(firstpassword.length < 8){ alert("**Password length must be atleast 8 characters"); return false; } //maximum length of password validation if(firstpassword.length > 15) { alert("**Password length must not exceed 15 characters"); return false; } /* if(secondpassword==null || secondpassword==""){ alert("Please retype password"); return false; }*/ } </script> <form action="/SMT.php" name="regForm" onsubmit="returnvalidateForm()" enctype="multipart/form-data" method="POST"> <p> Password </p> <input type='password' class='input' name='password'> <p> Re-type Password </p> <input type='password' class='input' name='password2'> <input type='submit' value='SUBMIT' class='input' name='Submit' style='text-align:center;'> </form> </html>