当前位置:网站首页>Common verification rules of form components -1 (continuously updating ~)
Common verification rules of form components -1 (continuously updating ~)
2022-07-04 20:36:00 【51CTO】
Preface
I feel more and more deeply recently , It's about sharing often , Share your own pitfalls , Share your solutions , Share your experiences , It's very necessary . because , My first reaction when I encounter a problem is to see how others solve it , Someone must have the same idea , At this time, we all need to share very generously . therefore , In the future, I will try to summarize and share regularly , It's convenient for others and for yourself ~
Reference link
https://element.eleme.io/#/zh-CN/component/form
https://github.com/yiminghe/async-validator
Introduction to form verification
Purpose of use
On the premise of preventing users from making mistakes , Let users find and correct errors as early as possible .
Easy to use
Form Component provides the function of form validation , Just go through rules
Property to pass in the validation rules of the contract , And will Form-Item Of prop
Property is set to the field name to be verified .
< el - form : model = "ruleForm" : rules = "rules" ref = "ruleForm" label - width = "100px" class = "demo-ruleForm" >
< el - form - item label = " The name of the event " prop = "name" >
< el - input v - model = "ruleForm.name" > < /el-input>
< /el-form-item>
< el - form - item >
< el - button type = "primary" @ click = "submitForm('ruleForm')" > Create... Now < /el-button>
< el - button @ click = "resetForm('ruleForm')" > Reset < /el-button>
< /el-form-item>
< /el-form>
< script >
export default {
data() {
return {
ruleForm: {
name: '',
},
rules: {
name: [
{ required: true, message: ' Please enter the activity name ', trigger: 'blur' },
{ min: 3, max: 5, message: ' The length is in 3 To 5 Characters ', trigger: 'blur' }
],
}
};
},
methods: {
submitForm( formName) {
this. $refs[ formName]. validate(( valid) => {
if ( valid) {
alert( 'submit!');
} else {
console. log( 'error submit!!');
return false;
}
});
},
resetForm( formName) {
this. $refs[ formName]. resetFields();
}
}
}
< /script>
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
Common field
required
Is it required , Used to verify whether the field content is empty ;
type
data type , Similar data format verification , The default is string, Common types are number
,boolean
,integer
,float
,array
,date
,email
etc. ;
pattern
Only when the field value matches the regular expression can it pass the validation ;
min
and max
about string And arrays ,min and max Represents the minimum and maximum length ; For numbers number Come on , Indicates the size of the limit value ;
trigger
Conditions that trigger validation ;
validator
You can customize the validation function for the specified field :function(rule, value, callback);
边栏推荐
- Process of manually encrypt the mass-producing firmware and programming ESP devices
- c# . Net MVC uses Baidu ueditor rich text box to upload files (pictures, videos, etc.)
- 应用实践 | 蜀海供应链基于 Apache Doris 的数据中台建设
- Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
- Length of the longest integrable subarray
- C # better operation mongodb database
- Key rendering paths for performance optimization
- 凌云出海记 | 一零跃动&华为云:共助非洲普惠金融服务
- Integritee通过XCM集成至Moonriver,为其生态系统带来企业级隐私解决方案
- What is involution?
猜你喜欢
Form组件常用校验规则-1(持续更新中~)
水晶光电:长安深蓝SL03的AR-HUD产品由公司供应
Cbcgptabwnd control used by BCG (equivalent to MFC TabControl)
Regular replacement [JS, regular expression]
Abc229 summary (connected component count of the longest continuous character graph in the interval)
Flet教程之 08 AppBar工具栏基础入门(教程含源码)
node强缓存和协商缓存实战示例
实践示例理解js强缓存协商缓存
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
Understand the reading, writing and creation of files in go language
随机推荐
Lingyun going to sea | 10 jump &huawei cloud: jointly help Africa's inclusive financial services
Wireshark network packet capture
华为云云商店首页 Banner 资源位申请
Win11系统wifi总掉线怎么办?Win11系统wifi总掉线的解决方法
精选综述 | 用于白内障分级/分类的机器学习技术
HMM hidden Markov model and code implementation
更强的 JsonPath 兼容性及性能测试之2022版(Snack3,Fastjson2,jayway.jsonpath)
PHP pseudo original API docking method
Process of manually encrypt the mass-producing firmware and programming ESP devices
Thinking on demand development
Six stones programming: about code, there are six triumphs
Win11无法将值写入注册表项如何解决?
Decryption function calculates "task state and lifecycle management" of asynchronous task capability
Pytoch learning (4)
node强缓存和协商缓存实战示例
Key rendering paths for performance optimization
电脑页面不能全屏怎么办?Win11页面不能全屏的解决方法
【深度学习】一文看尽Pytorch之十九种损失函数
MySQL中的日期时间类型与格式化方式
What does the neural network Internet of things mean? Popular explanation