Simple Signup form with strong username and password validation
This a simple javascript function to validate the name and password as our requirements before the user submit the form.
In this i have used the Regex To create my requirements
Name Validation
function userNameValidation(usernameInput) { var issueArr = []; if (/[[email protected]#$%^&*()_+|~=`{}\[\]:";'<>?,.\/]/.test(usernameInput)) { issueArr.push("No special characters!"); } return issueArr; }
Password Validation
function passwordValidation(passwordInput) { var issueArr = []; if (!/^.{6,8}$/.test(passwordInput)) { issueArr.push("Password must be between 6-8 characters."); } if (!/\d/.test(passwordInput)) { issueArr.push("Must contain at least one number."); } if (!/[a-z]/.test(passwordInput)) { issueArr.push("Must contain a lowercase letter."); } if (!/[A-Z]/.test(passwordInput)) { issueArr.push("Must contain an uppercase letter."); } return issueArr; }
Then Using the HTMLSelectElement.setCustomValidity()
method sets the custom validity message for the selection element to the specified message.
You can run the html file to see the output.
I am a beginner so you can suggest me any thing that i can work on.
Thanks.
Comments
Leave a comment
You are not LoggedIn but you can comment as an anonymous user which requires manual approval. For better experience please Login.