Thomas
Thomas

Reputation: 10669

How to convert MySQL datatype names into regular expressions using php?

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}$/

Upvotes: 1

Views: 410

Answers (1)

Eli
Eli

Reputation: 5610

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?

Upvotes: 1

Related Questions