Brian
Brian

Reputation: 27392

Alphabetic equivalent of PHP is_numeric

I am looking for a function that would be the alphabetic equivalent of is_numeric. It would return true if there are only letters in the string and false otherwise. Does a built in function exist in PHP?

Upvotes: 3

Views: 1317

Answers (4)

AlSayed Gamal
AlSayed Gamal

Reputation: 332

!is_numeric((float)$variableToBeChecked); also preg_match('#^[a-z]+$#i',$variableToBeChecked); // for one or more letter character

Upvotes: 0

Erik
Erik

Reputation: 20722

I would have used preg_match. But that's because I'd never heard of ctype_alpha().

if(!preg_match("/[^a-zA-Z]/", $teststring)) {
    echo "There are only letters in this string";
} else {
    echo "There are non-letters in this string";
}

Upvotes: 0

ehdv
ehdv

Reputation: 4603

If you're strictly looking for the opposite of is_numeric(), wouldn't !is_numeric() do the job for you? Or am I misunderstanding the question?

Upvotes: 1

gnud
gnud

Reputation: 78568

You want ctype_alpha()

Upvotes: 10

Related Questions