0

I want to place check in Full name field that full name field should accept space between first and last name using i am using strrpos() function for it but not working

John Conde
  • 217,595
  • 99
  • 455
  • 496

1 Answers1

1

You could use a regex...

if (preg_match("/(.+)( )(.+)/", $full_name))
{ 
// returns true if name is formed of two words with a space between
}

For even better validation, you can use \w although keep in mind that it will only match English word characters. See here for more info: Why does \w match only English words in javascript regex?

preg_match("/(\w+)( )(\w+)/", $full_name)
Community
  • 1
  • 1
nageeb
  • 2,002
  • 1
  • 13
  • 25
  • 2
    If it's names, why not `/(w+)( )(w+)/` to add some extra validation – danneth Sep 10 '12 at 06:57
  • That works as well. I'll update my answer, but also keep in mind that if the user is attempting to match non-english characters, I don't believe \w will work. – nageeb Sep 10 '12 at 16:40