Is there a php function to get regular expressions able to check if an input fits a certain MySQL data type?
In example:
$foo = get_regex_for_data_type("int(10) unsigned");
echo $foo;
would return something like:
/^[0-9]{1,10}$/
Is there a php function to get regular expressions able to check if an input fits a certain MySQL data type?
In example:
$foo = get_regex_for_data_type("int(10) unsigned");
echo $foo;
would return something like:
/^[0-9]{1,10}$/
No, there is not a PHP function to do that. You could write it yourself, but it would be very difficult to get it 100% right. For example, 0xFF is a perfectly valid value to insert into that field, but your regex would exclude it.
Perhaps there is another way to accomplish what you're trying to do? Is the problem that you're worried a value might be too large for the field?