I have some form validation done, but it's not very good. How do i make sure that users can only use a-z, A-Z, 0-9. (there for users would not be able to use special characters) - note: i have the php server side validation done but i want javascript also, thanks Here is the code i have so far: function validate_username(field,alerttxt) { with (field) { numofchar=value.length; if (numofchar<5) {alert(alerttxt);return false} else {return true} } } HTML: function validate_form(thisform) { with (thisform) { if (validate_username(username,"Ooops... Username must be at least 5 characters in length")==false) {username.focus();return false} HTML: how can i make sure that the $username only can have a-z, A-Z, 0-9
if (numofchar<5 || value.match(/[^a-z0-9]/i)) Code (markup): Also, you might want to update the message so it informs of this new check.
How can i change this line around so that if (numofchar<5 || value.match(/[^a-z0-9]/i)) HTML: The rules are: between 5 and 15 characters a-z A-Z 0-9 characters only thanks for your help
It's the same pattern as I gave you here. http://forums.digitalpoint.com/showthread.php?t=370927 if (!value.match(/^[a-z0-9]{5,15}$/i)) { // Error } Code (javascript):
Sorry, i'm new to all of this, i didn't think you could use the same format in Javascript as you could in PHP. Thanks a million nico_swd, your a big help, thanks
Sorry, i'm after running into a bit of a problem. If i use if (!value.match(/^[a-z0-9]{5,15}$/i)) HTML: If a users name is O'Neill it wont accept it becaue of the ' character in the name. How do i just change the if statement to only check if its {5,15} or is their a way that i can inlude certain character such as ' and , and -
Add them to the list inside [ and ]. Usually it will work except in a few cases. e.g. a hyphen has to be escaped or at the end of the list: if (!value.match(/^[a-z0-9',-]{5,15}$/i)) Code (markup):