kwichz
kwichz

Reputation: 2453

Check if a variable have only one letter or a specific string

I have my variable $_GET['artist'] and I'd like to check :

  1. if that variable have got only one letter, and this letter is from a to z (case sensitive, so A is not valid);
  2. or if that variable is all or other

How can I check it with regex and preg_match() on PHP?

Upvotes: 1

Views: 1661

Answers (1)

Markus Hedlund
Markus Hedlund

Reputation: 24244

if (preg_match('/^([a-z]|all|other)$/', $_GET['artist']) === 1) {
    // True
}

Assuming all and other should also be case sensitive.

Upvotes: 6

Related Questions