Finding invalid EANs (simply) With MySQL

This is post is now quite old and the the information it contains may be out of date or innacurate.

If you find any errors or have any suggestions to update the information please let us know or create a pull request on GitHub

Check out this little query for checking for obviously invalid EANs.

Note this is not checking the check digit for validity, it is purely looking for data that is in no way possibly an EAN number.

update products set ean = '' where ean != '' and ean not regexp '^[0-9]{13}$'

assuming you have a column called ean, this will empty the value for the EAN for any product that has dodgy data in there.

MySQL regex is actually very powerful and fast.

Tags: mysqlean