David David - 4 years ago 146
SQL Question

MySQL SELECT WHERE only digits, spaces and one slash

How can I SELECT my_column FROM my_table, but my_column may only contain digits (0-9), spaces ( ) and ONE slash (/). More than one slashes are not allowed (per field). Other characters are not allowed.

Can any body give me a hint how to do that?

Answer Source

Use regexp:

SELECT my_column
FROM my_table
WHERE my_column REGEXP '^[0-9 ]*/[0-9 ]*$';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download