I'm a PHP newbie, and even worse when it comes to regular expressions. So basically I'm looking for any feedback about whether I'm doing this right or not. I'm performing a check on some XHTML form input (a person's first name). I decided I only want to allow letters, dashes, and individual spaces. Here's what I've currently got:
PHP Code:
if (filter_var($Name, FILTER_VALIDATE_REGEXP,
array("options"=>array("regexp"=>"/[^A-Za-z\-][ ]{1}/"))))
{
// Bad input detected.
}
else
{
// Input looks good.
}
The
[^A-Za-z\-][ ]{1} regular expression I put together
seems to do what I want (at least in my rudimentary tests), but does it look okay to you? I will add more thorough checking later, right now I just wanna make sure I'm doing this basic checking properly. TIA.