I would like to know how to restrict users from entering anything but alphanumeric characters and no spaces into a textfield.
Thanks
Restricting what can be entered into a text field.
Moderator: General Moderators
well with php you can do a check after they submit.
Dont know if you have ever heard of regular expressions, but in my opinion.. thats the way to do it.
ereg function
Some info about regular expressions
they'll be able to enter whatever they want into the field..but after they submit you check it and if its wrong, just redirect them back to the form.
If you want to do it on input instantly then i think you're gonna have to think about javascript or ajax
Dont know if you have ever heard of regular expressions, but in my opinion.. thats the way to do it.
ereg function
Some info about regular expressions
they'll be able to enter whatever they want into the field..but after they submit you check it and if its wrong, just redirect them back to the form.
If you want to do it on input instantly then i think you're gonna have to think about javascript or ajax
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
ctype_alnum()... no regex needed.
If spaces are ok use this instead.
Code: Select all
preg_match('#^[a-z0-9\s]+$#i', $string);