1

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?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Harry
  • 3,301
  • 7
  • 27
  • 33

2 Answers2

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