简体   繁体   中英

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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM