David David - 1 month ago 11
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

Use regexp:

SELECT my_column
FROM my_table
WHERE my_column REGEXP '^[0-9 ]*/[0-9 ]*$';