Parcourir la source

添加校验规则

liusungtsun il y a 1 an
Parent
commit
3084ad7b02

+ 1 - 0
src/views/BONDED/index.vue

@@ -211,6 +211,7 @@ export default {
         ],
         yardNumber: [
           { required: true, message: "场站编号不能为空", trigger: "blur" },
+          { pattern: /^[1-9a-zA-Z]{1,}$/, message: '场站编号只能输入数字和字母', trigger: 'blur' }
         ],
         establishedTime: [
           { required: true, message: "成立时间不能为空", trigger: "blur" },

+ 30 - 3
src/views/CONTACTUS/index.vue

@@ -78,7 +78,7 @@
         <el-form-item label="单位名称" prop="title">
           <el-input v-model="form.depName" placeholder="请输入单位名称"></el-input>
         </el-form-item>
-        <el-form-item label="联系电话" prop="title">
+        <el-form-item label="联系电话" prop="telphone">
           <el-input v-model="form.telphone" placeholder="请输入联系电话"></el-input>
         </el-form-item>
         <el-form-item label="邮箱" prop="email">
@@ -98,11 +98,13 @@
 
 <script>
 import { listCONTACTUS, getCONTACTUS, delCONTACTUS, addCONTACTUS, updateCONTACTUS } from '@/api/portal/CONTACTUS/CONTACTUS.js';
+import { validEmail } from "@/utils/validate.js"
 
 export default {
   name: 'CONTACTUS',
   data() {
     return {
+      validEmail,
       // 根路径
       baseURL: process.env.VUE_APP_BASE_API,
       // 遮罩层
@@ -147,9 +149,12 @@ export default {
         delFlag: [{ required: true, message: '删除标志不能为空', trigger: 'blur' }],
         deptId: [{ required: true, message: '部门ID不能为空', trigger: 'blur' }],
         depName: [{ required: true, message: '单位名称不能为空', trigger: 'blur' }],
-        telphone: [{ required: true, message: '联系电话不能为空', trigger: 'blur' }],
+        telphone: [{ required: true, message: '联系电话不能为空', trigger: 'blur' },
+                { validator: this.validateMobile, trigger: 'blur' }],
         location: [{ required: true, message: '位置不能为空', trigger: 'blur' }],
-        email: [{ required: true, message: '邮箱不能为空', trigger: 'blur' }]
+        email: [{ required: true, message: '邮箱不能为空', trigger: 'blur' },
+                { validator: this.validEmailFun, trigger: 'blur' }
+      ]
       }
     };
   },
@@ -157,6 +162,28 @@ export default {
     this.getList();
   },
   methods: {
+    validEmailFun(rule, value, callback) {
+       if(this.validEmail(value)) {
+        callback()
+       }else {
+        callback(new Error('邮件格式不正确!'));
+       }
+    },
+    validateMobile(rule, value, callback) {
+      let reg1 = /^1[3|4|5|7|8][0-9]\d{8}$/;//11位手机号
+      let reg2 = /^(\d{3,4}-)?\d{6,8}$/;//座机和传真格式是一样的:区号-号码
+      console.log(!reg1.test(value) , !reg2.test(value));
+      if(!value && value!=='0'){
+        callback()
+      }else{
+        if (reg1.test(value) || reg2.test(value)) {
+          callback()
+        } else {
+          callback(new Error('请输入正确手机号!'));
+        }
+      }
+      
+    },
     /** 查询联系我们列表 */
     getList() {
       this.loading = true;

+ 3 - 1
src/views/FRIENDLYLINKS/index.vue

@@ -117,7 +117,9 @@ export default {
         delFlag: [{ required: true, message: '删除标记不能为空', trigger: 'blur' }],
         deptId: [{ required: true, message: '部门id不能为空', trigger: 'blur' }],
         linkName: [{ required: true, message: '友情链接名称不能为空', trigger: 'blur' }],
-        linkUrl: [{ required: true, message: '友情链接url不能为空', trigger: 'blur' }]
+        linkUrl: [{ required: true, message: '友情链接url不能为空', trigger: 'blur' },
+                 {pattern: /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\*\+,;=.]+$/, message: '请输入正确的url链接', trigger: 'blur' }
+           ]
       }
     };
   },

+ 31 - 3
src/views/ONLINE/index.vue

@@ -76,11 +76,13 @@
 
 <script>
 import { listONLINE, getONLINE, delONLINE, addONLINE, updateONLINE } from '@/api/portal/ONLINE/ONLINE';
+import { validEmail } from "@/utils/validate.js"
 
 export default {
   name: 'ONLINE',
   data() {
     return {
+      validEmail,
       // 根路径
       baseURL: process.env.VUE_APP_BASE_API,
       // 遮罩层
@@ -123,11 +125,15 @@ export default {
       rules: {
         id: [{ required: true, message: '主键不能为空', trigger: 'blur' }],
         delFlag: [{ required: true, message: '删除标志不能为空', trigger: 'blur' }],
-        deptId: [{ required: true, message: '部门id不能为空', trigger: 'blur' }],
+        deptId: [{ required: true, message: '单位编码不能为空', trigger: 'blur' },
+                 { pattern: /^[1-9a-zA-Z]{1,}$/, message: '单位编码只能输入数字和字母', trigger: 'blur' }
+                ],
         depName: [{ required: true, message: '单位名称不能为空', trigger: 'blur' }],
-        telphone: [{ required: true, message: '单位电话不能为空', trigger: 'blur' }],
+        telphone: [{ required: true, message: '单位电话不能为空', trigger: 'blur' },
+                  {validator: this.validateMobile, trigger: "blur"}],
         location: [{ required: true, message: '单位地址不能为空', trigger: 'blur' }],
-        email: [{ required: true, message: '单位邮箱不能为空', trigger: 'blur' }],
+        email: [{ required: true, message: '单位邮箱不能为空', trigger: 'blur' },
+                { validator: this.validEmailFun, trigger: 'blur' }],
         introduction:[{ required: true, message: '简介不能为空', trigger: 'blur' }]
       }
     };
@@ -136,6 +142,28 @@ export default {
     this.getList();
   },
   methods: {
+    validEmailFun(rule, value, callback) {
+       if(this.validEmail(value)) {
+        callback()
+       }else {
+        callback(new Error('邮件格式不正确!'));
+       }
+    },
+    validateMobile(rule, value, callback) {
+      let reg1 = /^1[3|4|5|7|8][0-9]\d{8}$/;//11位手机号
+      let reg2 = /^(\d{3,4}-)?\d{6,8}$/;//座机和传真格式是一样的:区号-号码
+      console.log(!reg1.test(value) , !reg2.test(value));
+      if(!value && value!=='0'){
+        callback()
+      }else{
+        if (reg1.test(value) || reg2.test(value)) {
+          callback()
+        } else {
+          callback(new Error('请输入正确手机号!'));
+        }
+      }
+      
+    },
     /** 查询网上办事列表 */
     getList() {
       this.loading = true;

+ 2 - 1
src/views/system/post/index.vue

@@ -198,7 +198,8 @@ export default {
           { required: true, message: "岗位名称不能为空", trigger: "blur" }
         ],
         postCode: [
-          { required: true, message: "岗位编码不能为空", trigger: "blur" }
+          { required: true, message: "岗位编码不能为空", trigger: "blur" },
+          { pattern: /^[1-9a-zA-Z]{1,}$/, message: '岗位编码只能输入数字和字母', trigger: 'blur' }
         ],
         postSort: [
           { required: true, message: "岗位顺序不能为空", trigger: "blur" }

+ 2 - 1
src/views/system/user/index.vue

@@ -438,7 +438,8 @@ export default {
         ],
         password: [
           { required: true, message: "登陆密码不能为空", trigger: "blur" },
-          { min: 5, max: 20, message: '登陆密码长度必须介于 5 和 20 之间', trigger: 'blur' }
+          { min: 5, max: 20, message: '登陆密码长度必须介于 5 和 20 之间', trigger: 'blur' },
+          { pattern: /^[1-9a-zA-Z]{5,20}$/, message: '密码只能输入数字和字母', trigger: 'blur' }
         ],
         email: [
           {