Reputation: 248
I made this function to check if the first character is a letter.
function isLetter($string) {
return preg_match('/^\s*[a-z,A-Z]/', $string) > 0;
}
However, if I check a sentence that starts with a coma (,
) the functions returns true
. What is the proper regex to check if the first letter is a-z or A-Z?
Upvotes: 3
Views: 2133
Reputation: 5302
A slightly cleaner way, in my opinion. Just makes the code a little more human readable.
function isLetter($string) {
return preg_match('/^[a-z]/i', trim($string));
}
Upvotes: 1