| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- const validators = {
- // 验证手机号码(简单验证,仅针对常见格式)
- phone: {
- pattern: /^1[3-9]\d{9}$/,
- message: '请输入正确的手机号码'
- },
- // 验证电子邮箱
- email: {
- pattern: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
- message: '请输入正确的电子邮箱地址'
- },
- // 验证身份证号码(简单验证,不考虑所有特殊情况)
- idCard: {
- pattern: /^\d{15}(\d{2}[a-zA-Z0-9])?$/,
- message: '请输入正确的身份证号码'
- },
- // 验证纯数字(可用于验证数量、页码等)
- number: {
- pattern: /^\d+$/,
- message: '请输入数字'
- },
- // 验证是否为正整数
- positiveInteger: {
- pattern: /^[1-9]\d*$/,
- message: '请输入正整数'
- },
- // 验证是否为非负整数(包含0和正整数)
- nonNegativeInteger: {
- pattern: /^\d*$/,
- message: '请输入非负整数'
- },
- // 验证是否包含中文
- chinese: {
- pattern: /[\u4e00-\u9fa5]+/,
- message: '请输入包含中文的内容'
- },
- // 验证是否只包含英文字母(大写或小写)
- englishLetters: {
- pattern: /^[a-zA-Z]+$/,
- message: '请输入只包含英文字母的内容'
- },
- // 验证是否只包含英文字母和数字
- englishLettersAndNumbers: {
- pattern: /^[a-zA-Z0-9]+$/,
- message: '请输入只包含英文字母和数字的内容'
- },
- // 验证密码强度(至少包含一个大写字母、一个小写字母、一个未雨绸缪、一个数字和一个特殊字符,长度至少8位)
- passwordStrength: {
- pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\w\s]).{8,}$/,
- message:
- '请输入至少包含一个大写字母、一个小写字母、一个数字和一个特殊字符,且长度至少8位的密码'
- },
- // 验证URL格式(简单验证)
- url: {
- pattern: /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/,
- message: '请输入正确的URL地址'
- },
- // 大于0小于1且最多两位小数验证
- decimalRange: {
- pattern: /^(0\.\d{1,2}|0[1-9]\d{0,1}\.\d{1,2}|1)$/,
- message: '请输入大于0小于1且最多两位小数的数值'
- },
- money:{
- pattern: /^(([1-9]{1}\d*)|([0]{1}))(\.\d{1,2})?$/,
- message:'请输入正确的金额'
- },
- };
- export default validators;
|