I was creating a function to validate large text fields (description, observation, ...), which in SQL will be saved as TEXT
, so basically I did this:
function($valor, $min = 0, $max = 65000) {
if (strlen($valor) >= $min || strlen($valor) <= $max) {
return true;
} else {
return false;
}
}
When I was looking for the maximum size of the fields of type TEXT
of the I found this question of the SOen that responds to this, and it shows that the size of the text depends on the characters of the string. In fact the text types do not have a character limit but a byte limit, then two questions:
-
How to validate a text entry according to the maximum bytes size that the string should contain?
-
This validation is required only in fields
TINYTEXT
,TEXT
,MEDIUMTEXT
, andLONGTEXT
?