I'm making a Full Name field and only want the user to be able to enter numbers, letters and spaces. How would that be done in an if statement?
Asked
Active
Viewed 155 times
1
-
Related, possibly a dupe: http://stackoverflow.com/q/4345621/2460971 – numaroth Mar 20 '15 at 13:28
2 Answers
4
You can go the opposite way and check if there are any illegal characters using, for instance:
if (preg_match("/[^a-z\\d ]/i", $input))
// illegal input

fge
- 119,121
- 33
- 254
- 329
1
Another solution,
if(preg_match('/[^\w\d ]/',$input)){
//illegal input
}

Adem Öztaş
- 20,457
- 4
- 34
- 42