-2

I am trying to capture the full name of users from one input field. I am trying to set up my code such that the input field should only accept alphanumeric characters.

I found this regex on the internet that I thought was gonna help but it's not working.

if(preg_match('/^[a-zA-Z0-9]+$/'){}

The regex only accepts the input when I write one word. Seems there is something wrong with accepting the second word due to the space between them.

How can I make the regex to accepts spaces and return true when I type more than two words?

Any help will be highly appreciated.

The fourth bird
  • 127,136
  • 16
  • 45
  • 63

0 Answers0