1

I'm using regex (I think that's what it's called - haha) to check my users' name to make sure it's valid. I want to make sure that the user doesn't have any characters. Just letters and spaces. I've got the only letters part down, but I can't get the spaces part fixed.

Here's what I'm using now..

if(preg_match("/[^a-zA-Z]/", " ", $name) != 0) {

        $errorlist = $errorlist."<li>You must enter a valid First and Last name (check for invalid characters)</li>";

}

Anyone see what I'm doing wrong?

4

1 に答える 1

1

正規表現パターンにスペースを追加するだけです。PS - preg_match() の 2 番目のパラメーターは、おそらく $name である必要があります。" " をテストした理由はありますか?

if(preg_match("/[^a-zA-Z ]/", $name) != 0) {
    $errorlist = $errorlist."<li>You must enter a valid First and Last name (check for invalid characters)</li>";
}
于 2013-05-15T00:21:39.820 に答える