Search code examples
mysqldatabasesecuritypattern-matchingserver-side

Doing a pattern match MySQL-side before data is inserted into a table?


I'm new to MySQL, and am wondering: Is it possible to make a table check attempted inserts against some sort of pattern match, and reject any inserts that fail to match the pattern, or must this checking all be done PHP / what-ever-server-side-language side?

I'm thinking specifically about confining an email column in a user table to only be able to contain email addresses using some sort of regex-like pattern matching.


Solution

  • Because you can do something with a DBMS stored procedure doesn't make it a good idea. I strongly suggest you do this kind of validation in PHP rather than in the DBMS.

    PHP's install kit contains a validator for email. See here: http://php.net/manual/en/filter.filters.validate.php

    If you do this in your DBMS you have to reinvent the flat tire, er, wheel.