sawade Posted September 10, 2009 Share Posted September 10, 2009 I have gone through the W3C section on RegExp, and am still not understanding the snytax. I have a code that allows for letters, numbers, and underscores. However, I want to modify it to only allow letters and nothing else. function validateFirstname(fld) { var error = ""; var illegalChars = /\W/; // allow letters, numbers, and underscores if (fld.value == "") { fld.style.background = 'Yellow'; error = "You didn't enter your FIRST NAME.\n"; } else if ((fld.value.length < 3) || (fld.value.length > 30)) { fld.style.background = 'Yellow'; error = "FIRST NAME is the wrong length.\n"; } else if (illegalChars.test(fld.value)) { fld.style.background = 'Yellow'; error = "FIRST NAME contains illegal characters.\n"; } else { fld.style.background = 'White'; } return error; } Thanks. Quote Link to comment Share on other sites More sharing options...
kratsg Posted September 11, 2009 Share Posted September 11, 2009 var illegalchars = /[^a-zA-Z]*/;//only allow letters Quote Link to comment Share on other sites More sharing options...
sawade Posted September 14, 2009 Author Share Posted September 14, 2009 THanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.