InputValidation.number constructor
InputValidation.number({})
数字校验 / Number validation
Example:
validator: InputValidation.number(errorMsg: "请输入数字").validate
Implementation
factory InputValidation.number({
String? errorMsg,
String? emptyTip,
bool mustFill = true,
bool allowDecimal = true,
bool allowNegative = true,
}) {
String pattern;
if (allowDecimal && allowNegative) {
pattern = r'^-?\d*\.?\d+$';
} else if (allowDecimal && !allowNegative) {
pattern = r'^\d*\.?\d+$';
} else if (!allowDecimal && allowNegative) {
pattern = r'^-?\d+$';
} else {
pattern = r'^\d+$';
}
return InputValidation(
mustFill: mustFill,
regExp: RegExp(pattern),
errorMsg: errorMsg ?? "请输入${allowNegative ? '' : '正'}${allowDecimal ? '数字' : '整数'}",
emptyTip: emptyTip ?? "数字不能为空",
);
}