PHP - preg_match()允许意外

I'm trying to use preg_match() to only allow chars from a-z. I'm using this string:

if (! preg_match('/[^a-z]/i', $name)) {
    echo 'Invalid characters in your name..';
    return false;
}

But for some reason it's allowing all characters. I've starred at those lines for long time now, and I don't get why it doesn't work.

Your Pattern only searches for one character that's why it will return true pretty much everytime if not the string only containt invalid characters.

change to this your pattern to this and you should be up and running

^[a-z]+$

if you want to allow uppercase letter too

^[A-za-z]+$

and perhaps nummbers

^[A-za-z0-9]+$

Edit: If you want to check a string for <> the you could use

(<|>)

but it will return true