oaziz
oaziz

Reputation: 1372

How can I check if the text contains at least one A to Z letter?

How can I write this in PHP?

if ($text contains at least one letter from A to Z, regardless of numbers or other characters)
    echo 'Yes';
else
    echo 'No';

Please help.

Upvotes: 0

Views: 2713

Answers (3)

tttony
tttony

Reputation: 5082

Use preg_match() function

if (preg_match('/[a-z]/i', $text))
    echo "Matches";
else
    echo "No matches";

Upvotes: 5

pv1
pv1

Reputation: 317

Like this

if (preg_match('/[A-Za-z]/i', $variable)) {

      echo 'Yes';
}
else {

      echo 'No';
}

Upvotes: 5

Jacob Eggers
Jacob Eggers

Reputation: 9322

Here's something that will help

preg_match("/[a-z]/i",$text);

Upvotes: 5

Related Questions