How to check for uppercase letters in MySQL?

R_User picture R_User · May 15, 2013 · Viewed 23.8k times · Source

I want to check, if a string consits only of uppercase letters. I know that RLIKE/REGEXP are not case sensitive in MySQL. So I tried to use the :upper: character class:

SELECT 'z' REGEXP '^[[:upper:]]+$';

This gives true, although the z is in lower case,... why?

Answer

Kyle Anderson picture Kyle Anderson · Sep 23, 2015

REGEXP is not case sensitive, except when used with binary strings.

http://dev.mysql.com/doc/refman/5.7/en/regexp.html

So with that in mind, just do something like this:

SELECT * FROM `users` WHERE `email` REGEXP BINARY '[A-Z]';

Using the above example, you'd get a list of emails that contain one or more uppercase letters.