hid*_*dar 2 vue.js vuejs2 vee-validate
我试图限制用户可以在3-6之间输入的位数.
出于某种原因,我找不到如何做到这一点.
这是我必须强制用户添加三位数的代码
<input type="text" name='account-field-3' v-validate="'required|digits:3'" placeholder="6" class="form-control" >
Run Code Online (Sandbox Code Playgroud)
但我需要的是3-6之间.
你需要使用min
和max
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" >
Run Code Online (Sandbox Code Playgroud)
它已经很长时间了,但这里有一个对我有用的解决方案。
//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'
});
Run Code Online (Sandbox Code Playgroud)
<!-- vue file -->
<ValidationProvider
rules="digits_between:3,8"
v-slot="{ errors }"
name="Country"
>
<input v-model="value" type="text">
<span>{{ errors[0] }}</span>
</ValidationProvider>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7130 次 |
最近记录: |