当前位置:网站首页>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);
边栏推荐
- Kotlin inheritance
- Employment prospects of neural network Internet of things application technology [welcome to add]
- Six stones programming: about code, there are six triumphs
- The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
- B2B mall system development of electronic components: an example of enabling enterprises to build standardized purchase, sale and inventory processes
- Flet教程之 06 TextButton基础入门(教程含源码)
- Understand the reading, writing and creation of files in go language
- [problem] Druid reports exception SQL injection violation, part always true condition not allow solution
- Oracle database, numbers Force 2 decimal places to display-Alibaba Cloud
- Related concepts of federal learning and motivation (1)
猜你喜欢
[ismb2022 tutorial] the picture shows the precision medicine of learning. Marinka zitnik, Harvard University, keynote speaker, with 87 ppt
精选综述 | 用于白内障分级/分类的机器学习技术
Detailed explanation of Audi EDI invoice message
Flet教程之 04 FilledTonalButton基础入门(教程含源码)
HMM hidden Markov model and code implementation
ACM组合计数入门
Process of manually encrypt the mass-producing firmware and programming ESP devices
On communication bus arbitration mechanism and network flow control from the perspective of real-time application
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
Crystal optoelectronics: ar-hud products of Chang'an dark blue sl03 are supplied by the company
随机推荐
Optimize if code with policy mode [policy mode]
Write it down once Net analysis of thread burst height of an industrial control data acquisition platform
[in-depth learning] review pytoch's 19 loss functions
Decryption function calculates "task state and lifecycle management" of asynchronous task capability
实践示例理解js强缓存协商缓存
SSRS筛选器的IN运算(即包含于)用法
ICML 2022 | meta proposes a robust multi-objective Bayesian optimization method to effectively deal with input noise
华为nova 10系列支持应用安全检测功能 筑牢手机安全防火墙
2022 version of stronger jsonpath compatibility and performance test (snack3, fastjson2, jayway.jsonpath)
Write it down once Net analysis of thread burst height of an industrial control data acquisition platform
Win11U盘拒绝访问怎么办?Win11U盘拒绝访问的有效解决方法
Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
1500万员工轻松管理,云原生数据库GaussDB让HR办公更高效
Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
So this is the BGP agreement
Practice examples to understand JS strong cache negotiation cache
Offset function and windowing function
c# .net mvc 使用百度Ueditor富文本框上传文件(图片,视频等)
HMM hidden Markov model and code implementation
【ISMB2022教程】图表示学习的精准医疗,哈佛大学Marinka Zitnik主讲,附87页ppt