shineout
Version:
Shein 前端组件库
22 lines (19 loc) • 629 B
JavaScript
import { isEmpty } from '../is';
export default (function (options) {
return function (value, _formdata, callback) {
var min = options.min,
max = options.max,
message = options.message;
var error = new Error(message);
if (isEmpty(value)) {
if (min) callback(error);else callback(true);
return;
}
var len = typeof value === 'number' ? value.toString().length : value.length;
if (len !== undefined && typeof min === 'number' && len < min || len !== undefined && typeof max === 'number' && len > max) {
callback(error);
} else {
callback(true);
}
};
});