1. 程式人生 > >vue + elementUi 實現密碼校驗

vue + elementUi 實現密碼校驗

 
<el-form-item v-else label="密碼" label-width='150px' prop="password">
   <el-input :placeholder="info.password" v-model="info.password" style="width: 500px"></el-input>
</el-form-item>
<el-form-item  v-else label="確認密碼" label-width='150px' prop="repassword">
   <el-input :placeholder="info.repassword" v-model="info.repassword" style="width: 500px"></el-input>
</el-form-item>
data() {
    var validatePass2 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('請再次輸入密碼'))
      } else if (value !== this.info.password) {
        callback(new Error('兩次輸入密碼不一致!'))
      } else {
        callback()
      }
    }
    return {
      info: {
      },
      rules: {
        password: [
          { required: true, message: '請輸入密碼', trigger: 'blur' },
          { pattern: /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_]+$)(?![a-z0-9]+$)(?![a-z\W_]+$)(?![0-9\W_]+$)[a-zA-Z0-9\W_]{8,30}$/, message: '密碼為數字,小寫字母,大寫字母,特殊符號 至少包含三種,長度為 8 - 30位,密碼不能包含 使用者名稱,公司名稱(lidian), 公司域名(rekoon) (判斷的時候不區分大小寫)' }
        ],
        repassword: [
          { required: true, validator: validatePass2, trigger: 'blur' }
        ]
      }
    }
  },