当前位置:网站首页>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);
边栏推荐
- Hash哈希竞猜游戏系统开发如何开发丨哈希竞猜游戏系统开发(多套案例)
- In the first month of its launch, the tourist praise rate of this campsite was as high as 99.9%! How did he do it?
- Form组件常用校验规则-1(持续更新中~)
- New wizard effect used by BCG
- 最长的可整合子数组的长度
- 什么是区块哈希竞猜游戏系统开发?哈希竞猜游戏系统开发(案例成熟)
- Small hair cat Internet of things platform construction and application model
- How is the entered query SQL statement executed?
- 实践示例理解js强缓存协商缓存
- HMM hidden Markov model and code implementation
猜你喜欢
Practical examples of node strong cache and negotiation cache
![[Beijing Xunwei] i.mx6ull development board porting Debian file system](/img/46/abceaebd8fec2370beec958849de18.jpg)
[Beijing Xunwei] i.mx6ull development board porting Debian file system

Employment prospects and current situation of Internet of things application technology

Win11系统wifi总掉线怎么办?Win11系统wifi总掉线的解决方法

On communication bus arbitration mechanism and network flow control from the perspective of real-time application

Pytoch learning (4)

QT writing the Internet of things management platform 38- multiple database support

Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation

How to adapt your games to different sizes of mobile screen

Neural network IOT platform construction (IOT platform construction practical tutorial)
随机推荐
复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
2022 Health Exhibition, Beijing Health Expo, China Health Exhibition, great health exhibition November 13
Pytoch learning (4)
Abc229 summary (connected component count of the longest continuous character graph in the interval)
左右最值最大差问题
什么叫内卷?
Process of manually encrypt the mass-producing firmware and programming ESP devices
Regular replacement [JS, regular expression]
C server log module
[graduation season] green ant new fermented grains wine, red mud small stove. If it snows late, can you drink a cup?
Detailed explanation of Audi EDI invoice message
Lingyun going to sea | Wenhua online & Huawei cloud: creating a new solution for smart teaching in Africa
Application practice | Shuhai supply chain construction of data center based on Apache Doris
Dark horse programmer - software testing - 09 stage 2-linux and database -31-43 instructions issued by modifying the file permission letter, - find the link to modify the file, find the file command,
Informatics Olympiad 1336: [example 3-1] find roots and children
Small hair cat Internet of things platform construction and application model
Related concepts of federal learning and motivation (1)
SSRS筛选器的IN运算(即包含于)用法
输入的查询SQL语句,是如何执行的?