html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css" />
<link rel="stylesheet" href="style.css">
<script src="js/jquery-3.3.1.js"></script>
<script src="js/jquery-ui.js"></script>
<script src="js/jquery.validate.js"></script>
<script src="js/inputmask.js"></script>
<script src="js/inputmask.numeric.extensions.js"></script>
<script src="js/jquery.inputmask.js"></script>
<script src="js/script.js"></script>
/head>
<body>
<form class="myform">
<h2>Enter sum</h2>
<div>
<input class="numberInputUs" name="numberUs" type="text" />
</div>
<br />
<br />
</form>
<hr />
</body>
</html>
脚本
$(document).ready(function () {
$('.myform').validate({
rules: {
numberUs: {
required: true,
range: [2, 100000000]
},
},
});
validateAfterLossFocus();
setAliasForCurrency();
$("input").val('');
setMaskInput();/
});
function validateAfterLossFocus() {
$('input').on('blur', function () {
$(this).submit();
})
}
function setAliasForCurrency(){
Inputmask.extendAliases({
us: {
prefix: "$",
groupSeparator: ".",
alias: "numeric",
placeholder: "0",
autoGroup: !0,
digits: 2,
digitsOptional: !1,
clearMaskOnLostFocus: !1,
allowMinus: 'false'
}
});
}
function setMaskInput() {
//$('.numberInputUs').inputmask("currency");
//$('.numberInputUs').inputmask({ alias: "currency", prefix: '' });
$('.numberInputUs').inputmask({ alias: "us" });
}
在InputMask中使用此类参数时,例如: -prefix,groupseparator,数字,然后验证工作不正确。 如何确保既保留格式又要正确验证格式。
我认为'占位符'和'分隔符',验证器被识别为符号,并将其考虑在内...
更新2
我写了这样的代码。
Inputmask.extendAliases({
byn: {
min: 2,
max: 200000,
prefix: "$",
groupSeparator: ".",
alias: "numeric",
placeholder: "0",
autoGroup: !0,
digits: 2,
digitsOptional: !1,
clearMaskOnLostFocus: !1,
allowMinus: 'false',
}
});
但是用户感到困惑,您不能输入更多的数字。此外,还可以如何添加错误输入数字的警报