This is still not right.

min/max refer to the magnitude of the value, maxlength refers to the number of digits in the value. For a max=1000, maxlength=4.

maxlength could perhaps be a ceil(log10(max)).