gpt4 book ai didi

javascript - 如何验证语义用户界面中的小数字段?

转载 作者:行者123 更新时间:2023-12-01 01:45:31 25 4
gpt4 key购买 nike

在semantic-ui中,是否可以验证十进制数字?对于可以轻松设置的整数:

$('.ui.form')
.form({
fields: {
field1: {
rules: [
{
type : 'integer[1..20]',
}
]
},
....

并且仅当整数落入指定范围时才验证该整数。我需要对十进制输入执行相同的操作(需要落入 1.99 - 100.99 的范围内),但用于整数的相同方法似乎不起作用。
我怎样才能实现这个目标?谢谢。

最佳答案

我是这样解决这个问题的:

$(document).ready(function() {

$.fn.form.settings.rules.greaterThan = function (inputValue, validationValue) {
return inputValue >= validationValue;
};
$.fn.form.settings.rules.smallerThan = function (inputValue, validationValue) {
return inputValue <= validationValue;
}
$('.ui.form')
.form({
on: 'blur',
fields: {
decimal: {
rules: [
{
type : 'decimal',
prompt : 'Please enter a decimal number here'
},
{
type: 'greaterThan[1.99]',
prompt: 'The price should be greater than 1.99',
},
{
type: 'smallerThan[100.99]',
prompt: 'The price should be less than 100.99',
},
]
},
}
})
;
});

通过这种方式,您将验证三个规则,这些规则结合起来可以获得所需的结果。

关于javascript - 如何验证语义用户界面中的小数字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51999545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com