当前位置:网站首页>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);
边栏推荐
- Is it safe for Great Wall Securities to open an account? Stock account opening process online account opening
- Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
- Pointnet / pointnet++ point cloud data set processing and training
- 华为nova 10系列支持应用安全检测功能 筑牢手机安全防火墙
- What does the neural network Internet of things mean? Popular explanation
- 精选综述 | 用于白内障分级/分类的机器学习技术
- Lingyun going to sea | Murong Technology & Huawei cloud: creating a model of financial SaaS solutions in Africa
- 实践示例理解js强缓存协商缓存
- Thinking on demand development
- Integritee通过XCM集成至Moonriver,为其生态系统带来企业级隐私解决方案
猜你喜欢

c# .net mvc 使用百度Ueditor富文本框上传文件(图片,视频等)

FS8B711S14电动红酒开瓶器单片机IC方案开发专用集成IC

Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines

Huawei Nova 10 series supports the application security detection function to build a strong mobile security firewall

Aiming at the "amnesia" of deep learning, scientists proposed that based on similarity weighted interleaved learning, they can board PNAS

Crystal optoelectronics: ar-hud products of Chang'an dark blue sl03 are supplied by the company
![[Beijing Xunwei] i.mx6ull development board porting Debian file system](/img/46/abceaebd8fec2370beec958849de18.jpg)
[Beijing Xunwei] i.mx6ull development board porting Debian file system

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

实战模拟│JWT 登录认证

水晶光电:长安深蓝SL03的AR-HUD产品由公司供应
随机推荐
Actual combat simulation │ JWT login authentication
ICML 2022 | meta proposes a robust multi-objective Bayesian optimization method to effectively deal with input noise
漫谈客户端存储技术之Cookie篇
2022 version of stronger jsonpath compatibility and performance test (snack3, fastjson2, jayway.jsonpath)
Chrome development tool: what the hell is vmxxx file
Offset function and windowing function
Win11U盘拒绝访问怎么办?Win11U盘拒绝访问的有效解决方法
2022 Health Exhibition, Beijing Health Expo, China Health Exhibition, great health exhibition November 13
Is it safe for Great Wall Securities to open an account? Stock account opening process online account opening
Swagger suddenly went crazy
Why is the maximum speed the speed of light
What is the application technology of neural network and Internet of things
九齐NY8B062D MCU规格书/datasheet
[in-depth learning] review pytoch's 19 loss functions
Process of manually encrypt the mass-producing firmware and programming ESP devices
YOLOv5s-ShuffleNetV2
九齐单片机NY8B062D单按键控制4种LED状态
Thinking on demand development
Talking about cookies of client storage technology
Win11无法将值写入注册表项如何解决?