I'm working on writing a php script that will loop through all tables in database and look for plain text credit card numbers. For this I'm using MySQL REGEXP. I need only those results which "only" contains credit card numbers. If there is any textual data that contains credit card number then the script should not consider it.
e.g.
| id | ccno |
| 1 | 4111111111111111 |
| 2 | 4111 1111 1111 1111 |
| 3 | 4111-1111-1111-1111 |
| 4 | some text 4111111111111111 some text |
If the query is trieggered on above table then it should return first 3 records, it should not return 4th record. For this purpose I'm using below query and the issue I'm facing is the query is returning all the 4 records.
SELECT ccno FROM aacc WHERE
(ccno = REGEXP '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR ccno = REGEXP '[0-9][0-9][0-9][0-9] [0-9][0-9][0-9][0-9] [0-9][0-9][0-9][0-9] [0-9][0-9][0-9][0-9]'
OR ccno = REGEXP '[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]')