Ok i want to check an input field on letters and spaces and a space must be followed by a letter...
^([a-z]+)$ checks on letters... but what am i supposed to add to allow a space?
Thanx in advance
regexp letters+spaces
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
\w matches far more than simply letters.
Is there an actual problem with spaces though? trim() should probably be used anyways..
Code: Select all
[feyd@home]>php -r "$t = array('last word should pass', 'last word should fail '); foreach($t as $a) { preg_match_all('#^[a-z]+(?:\s[a-z]+)*$#mi', $a, $matches); print_r($matches); }"
Array
(
[0] => Array
(
[0] => last word should pass
)
)
Array
(
[0] => Array
(
)
)