bugzy Posted August 9, 2012 Share Posted August 9, 2012 Hello guys.. I'm not into regex yet How will I edit this regex so it would allow letters only and spaces? preg_match('/^\pL+$/u', $fname) Link to comment https://forums.phpfreaks.com/topic/266864-how-to-add-spaces-on-this-regex/ Share on other sites More sharing options...
Christian F. Posted August 9, 2012 Share Posted August 9, 2012 What you want is a Character Class. Link to comment https://forums.phpfreaks.com/topic/266864-how-to-add-spaces-on-this-regex/#findComment-1368136 Share on other sites More sharing options...
Pikachu2000 Posted August 9, 2012 Share Posted August 9, 2012 You don't need a regex pattern at all for that. if( ctype_alpha( str_replace(' ', '', $string)) ) { echo 'Valid'; } else { echo 'Invalid'; } Link to comment https://forums.phpfreaks.com/topic/266864-how-to-add-spaces-on-this-regex/#findComment-1368164 Share on other sites More sharing options...
bugzy Posted August 9, 2012 Author Share Posted August 9, 2012 You don't need a regex pattern at all for that. if( ctype_alpha( str_replace(' ', '', $string)) ) { echo 'Valid'; } else { echo 'Invalid'; } Thanks Pikachu2000! This works! Link to comment https://forums.phpfreaks.com/topic/266864-how-to-add-spaces-on-this-regex/#findComment-1368177 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.