vue el-form表单校验以及常用正则

rules: {
str: [
{ required: true, message: ‘请输入活动名称’, trigger: ‘blur’ }, // 限制必填
{ min: 3, max: 5, message: ‘长度在 3 到 5 个字符’, trigger: ‘blur’ }, // 限制字符串长度
{ required: true, trigger: ‘blur’, validator: checkFinanceCode } // 自定义正则
]
}
};
},
methods: {
submitForm(formName) {
this.KaTeX parse error: Expected 'EOF', got '}' at position 137: …alse; } }); }̲, resetForm(fo…refs[formName].resetFields();
}
}
}


下面记录一下常用正则,大家发现错误,或者有更好的评论区提出来,我一并添加修改,方便大家下次直接用



// 数字类型
数字:/1*KaTeX parse error: Undefined control sequence: \d at position 11: / n位的数字:/^\̲d̲{n}/
至少n位的数字:/^\d{n,}KaTeX parse error: Undefined control sequence: \d at position 13: / m-n位的数字:/^\̲d̲{m,n}/
价格:/([1-9]([0-9]+)?(.[0-9]{1,2})?$)|(^(0){1}$)|([0-9].0-9?KaTeX parse error: Undefined control sequence: \* at position 29: …/^(0|[1-9][0-9]\̲*̲)/
非零开头的最多带两位小数的数字:/^([1-9][0-9]*)+(.[0-9]{1,2})?KaTeX parse error: Undefined control sequence: \- at position 20: …-2位小数的正数或负数:/^(\̲-̲)?\d+(\.\d{1,2}…/
正数、负数、和小数:/^(-|+)?\d+(.\d+)? / 有两位小数的正实数: / [ 0 − 9 ] + ( [ ˙ 0 − 9 ] 2 ) ? / 有两位小数的正实数:/^[0-9]+(\.[0-9]{2})? /有两位小数的正实数:/[09]+([˙09]2)?/
有1~3位小数的正实数:/2+(.[0-9]{1,3})?KaTeX parse error: Undefined control sequence: \d at position 17: … 非零的正整数:/^[1-9]\̲d̲\*/ 或 /^([1-9][0-9]*){1,3}KaTeX parse error: Undefined control sequence: \+ at position 7: / 或 /^\̲+̲?[1-9][0-9]\*/
非零的负整数:/^-[1-9][]0-9"*KaTeX parse error: Undefined control sequence: \d at position 13: / 或 /^-[1-9]\̲d̲\*/
非负整数:/^\d+KaTeX parse error: Undefined control sequence: \d at position 12: / 或 /^[1-9]\̲d̲\*|0/
非正整数:/^-[1-9]\d*|0KaTeX parse error: Undefined control sequence: \d at position 10: / 或 /^((-\̲d̲+)|(0+))/
非负浮点数:/^\d+(.\d+)?KaTeX parse error: Undefined control sequence: \d at position 12: / 或 /^[1-9]\̲d̲\*\.\d\*|0\.\d\…/
非正浮点数:/^((-\d+(.\d+)?)|(0+(.0+)?))KaTeX parse error: Undefined control sequence: \d at position 15: / 或 /^(-([1-9]\̲d̲\*\.\d\*|0\.\d\…/
正浮点数:/3\d*.\d*|0.\d*[1-9]\d*KaTeX parse error: Undefined control sequence: \* at position 22: …(([0-9]+\.[0-9]\̲*̲[1-9][0-9]\*)|(…/
负浮点数:/^-([1-9]\d*.\d*|0.\d*[1-9]\d*)KaTeX parse error: Undefined control sequence: \* at position 24: …(([0-9]+\.[0-9]\̲*̲[1-9][0-9]\*)|(…/
浮点数:/^(-?\d+)(.\d+)?KaTeX parse error: Undefined control sequence: \d at position 15: / 或 /^-?([1-9]\̲d̲\*\.\d\*|0\.\d\…/
// 其他特殊校验
4~20位英文+数字: /^(?![0-9]+ ) ( ? ! [ a − z A − Z ] + )(?![a-zA-Z]+ )(?![azAZ]+)[0-9A-Za-z]{4,20} / 大写英文 : / [ A − Z ] + / 大写英文: /^[A-Z]+ /大写英文:/[AZ]+/
邮箱: /4+[@][0-9a-zA-Z_.-]+([.][a-zA-Z]+)KaTeX parse error: Undefined control sequence: \w at position 7: / 或 /^\̲w̲+([-+.]\w+)\*@\…/
手机: /^1[3456789]\d{9}KaTeX parse error: Undefined control sequence: \d at position 70: …2|3|5|6|7|8|9])\̲d̲{8}/
只能汉字: /5{0,}KaTeX parse error: Can't use function '\(' in math mode at position 93: …和"XXXXXXXX):/^(\̲(̲\d{3,4}-)|\d{3.…/
强密码(必须包含大小写字母和数字的组合,不能使用特殊字符,长度在 8-10 之间):/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{8,10}KaTeX parse error: Undefined control sequence: \* at position 49: …在8-10之间):/^(?=.\̲*̲\d)(?=.\*[a-z])…/

#### 后话

-------------------------------------------------------------



对于面试,说几句个人观点。



面试,说到底是一种考试。正如我们一直批判应试教育脱离教育的本质,为了面试学习技术也脱离了技术的初心。但考试对于人才选拔的有效性是毋庸置疑的,几千年来一直如此。除非你有实力向公司证明你足够优秀,否则,还是得乖乖准备面试。这也并不妨碍你在通过面试之后按自己的方式学习。
其实在面试准备阶段,个人的收获是很大的,我也认为这是一种不错的学习方式。首先,面试问题大部分基础而且深入,这些是平时工作的基础。就好像我们之前一直不明白学习语文的意义,但它的意义就在每天的谈话间。

所谓面试造火箭,工作拧螺丝。面试往往有更高的要求,也迫使我们更专心更深入地去学习一些知识,也何尝不是一种好事。

  1. 0-9 ↩︎

  2. 0-9 ↩︎

  3. 1-9 ↩︎

  4. 0-9a-zA-Z_.- ↩︎

  5. \u4e00-\u9fa5 ↩︎

  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值