Jump to content

check for letters and spaces


fugix

Recommended Posts

I'm not a regular expressions expert, but the following code should work:

 

<?php
$s = 'php @freaks';
if (!preg_match('/[^a-z\s]/i', $s)) {
echo 'Contains only Letters and Spaces!';
} else {
echo 'Contains garbage data!';	
}
?>

 

The regex will return TRUE if it finds any characters except letters and spaces. If it finds only letters and spaces, will return FALSE.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.