check if the string contains alphabets in php

user1765876 picture user1765876 · Mar 17, 2014 · Viewed 34.9k times · Source

How to check if the string has alphabets in PHP

The ctype_alpha and ctype_digit doesn't help in it. is their any method?

Answer

Sabuj Hassan picture Sabuj Hassan · Mar 17, 2014

You can use preg_match for this.

if(preg_match("/[a-z]/i", $string)){
    print "it has alphabet!";
}

If you want to check for all the characters to be alphabet, then use anchor around the regex. For example ^[a-z]+$.