我正在尝试限制用户可以输入的位数在3-6之间。
因为某些原因,我不知道该怎么做。
这是我必须强制用户仅添加三位数的代码
<input type="text" name='account-field-3' v-validate="'required|digits:3'" placeholder="6" class="form-control" >
但我需要的是在3-6之间。
发布于 2018-02-02 22:15:42
您需要使用min
和max
最大:https://baianat.github.io/vee-validate/guide/rules.html#max
最小值:https://baianat.github.io/vee-validate/guide/rules.html#min
<input type="text" name='account-field-3' v-validate="'required|min:3|max:6'" placeholder="6" class="form-control" >
发布于 2020-04-16 19:41:35
它已经很久了,但这里有一个解决方案,它对我有效。
//Javascript File
import { min, max, numeric } from "vee-validate/dist/rules";
import { extend, validate, localize } from "vee-validate";
import en from "vee-validate/dist/locale/en.json";
localize({
en
});
extend("min", min);
extend("max", max);
extend("numeric", numeric);
extend('digits_between', {
async validate(value, { min, max }) {
const res = await validate(value, `numeric|min:${min}|max:${max}`,)
return res.valid;
},
params: ['min', 'max'],
message: 'The {_field_} must be between {min} and {max} digits'
});
<!-- vue file -->
<ValidationProvider
rules="digits_between:3,8"
v-slot="{ errors }"
name="Country"
>
<input v-model="value" type="text">
<span>{{ errors[0] }}</span>
</ValidationProvider>
https://stackoverflow.com/questions/48584469
复制相似问题