php - preg_match(_all) with a rule for every space character -


i trying create way of making sure every space has @ least 3 characters (a-za-z , single quotes allowed) on each side of it. that, first space. not rest of them. tried preg_match_all() no avail, hence question/post guys.

<?php   function validatespaces($str) {     if ( strpos( $str, ' ' ) !== false && !preg_match( '/(([a-z\']{3,})([ ]{1})([a-z\']{3,}))/i', $str ) )       return false;      return true;   }    echo validatespaces( 'hey there' ); // valid (correct)   echo validatespaces( 'he there' ); // invalid (correct)   echo validatespaces( 'hey ther e' ); // valid (incorrect) ?> 

as can see, first 2 examples working should, second 1 validates although second space has 1 character on right side of it. not want.

any or attempt appreciated!

thank in advance, chris.

last modification, macth if have ony 1 space (trim string before trying match it):

 ^([a-z']{3,} ?)+$ 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -