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
Asked
Active
Viewed 1,484 times
0

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

aqsa jamil
- 1
- 2
1 Answers
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)
-
2If 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