KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I want to enforce that the input firstname should only contains characters A-Z, a-z, and - the input login name should only contains alphanumeric characters How do I restrict the two rules in javascript? Below is my code (jsp) for username regex. But it's not working properly. function validateForm(){ var nameRegex = /^[a-zA-Z\-]+$/; var validfirstUsername = document.frm.firstName.value.match(nameRegex); if(validUsername == null){ alert("Your first name is not valid. Only characters A-Z, a-z and '-' are acceptable."); document.frm.firstName.focus(); return false; } } Thanks!
Tags (comma-separated)
Save Edits
Cancel