gpt4 book ai didi

javascript - 最小/最大验证 - Vuetify

转载 作者:行者123 更新时间:2023-12-03 06:44:13 26 4
gpt4 key购买 nike

我需要确保只能输入 5,000 到 50,000 之间的数字。我目前正在使用以下代码,

rules: {
required: value => !!value || 'Required.',
loanMin: value => value <= 5000 || 'Loan should be above £5000',
loanMax: value => value >= 50000 || 'Max should not be above £50,000',
}
应用到该字段的规则如下:
<v-text-field 
height="5"
:rules="[rules.loanMin, rules.loanMaxMax, rules.required]"
editable
v-model="sliderLoan"
@change="principleLogger(sliderLoan)"
persistent-hint
outline
label="Loan Amount"
type="number"
></v-text-field>

如何将多个规则应用于一个字段?

最佳答案

在您的模板中

<v-text-field
label="Example"
v-model="example"
:rules="exampleRules"
></v-text-field>
在数据
example: "",
exampleRules: [
v => !!v || "This field is required",
v => ( v && v >= 5000 ) || "Loan should be above £5000",
v => ( v && v <= 50000 ) || "Max should not be above £50,000",
],
引用: https://vuetifyjs.com/en/components/forms/ ,检查操场下的示例代码。
奖金:不是这个问题的一部分,而是相关的,稍作更改后,您可以将其用于最小/最大长度验证。
example: "",
exampleRules: [
v => !!v || "This field is required",
v => ( v && v.length >= 10 ) || "This field must have atleast 10 characters",
v => ( v && v.length <= 100 ) || "This field exceeds maximum allowed characters",
],

关于javascript - 最小/最大验证 - Vuetify,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56835707/

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