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. Link to comment https://forums.phpfreaks.com/topic/173802-solved-regexp-help/ 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 Link to comment https://forums.phpfreaks.com/topic/173802-solved-regexp-help/#findComment-916680 Share on other sites More sharing options...
sawade Posted September 14, 2009 Author Share Posted September 14, 2009 THanks. Link to comment https://forums.phpfreaks.com/topic/173802-solved-regexp-help/#findComment-918401 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.