1.vue檢查用戶名是否重復
-
-
只需要修改
components\axios_api\http.js
中調用的后端地址
// axios.defaults.baseURL = "http://127.0.0.1:8000/"
axios.defaults.baseURL = "http://192.168.56.100:8888/"
// 檢查用戶名 是否使用
check_username() { console.log('判斷用戶名') console.log(this.username == '') var reg = new RegExp(/^[a-zA-Z0-9_-]{3,16}$/); //字符串正則表達式 4到14位(字母,數字,下划線,減號)
if (this.username == '') { this.username_message = '用戶名不能為空'
this.username_error = true
return false } if (!reg.test(this.username)) { this.username_message = '用戶名格式不正確'
this.username_error = true
return false } else { // 去后端檢查用戶名使用數量
user_count({ type: 'username', data: this.username }).then((res) => { console.log(res) if (res.data.count > 0) { this.username_message = '用戶名已存在'
this.username_error = true } else { this.username_message = ''
this.username_error = false } }) } },
// 檢查手機號是否使用
check_phone() { console.log('檢查手機號') var reg = new RegExp(/^[1]([3-9])[0-9]{9}$/) if (this.phone == '') { this.phone_message = '手機號不能為空'
this.phone_error = true } if (!reg.test(this.phone)) { this.phone_message = '手機號格式不正確'
this.phone_error = true
return false } else { // 去后端查用戶數量
user_count({ type: 'phone', data: this.phone }).then((res) => { console.log(res) if (res.data.count > 0) { this.phone_message = '手機號已存在'
this.phone_error = true } else { this.phone_message = ''
this.phone_error = false } }) } },
3.VUE檢查密碼的復雜度
// 檢查密碼是否正確 check_password() { console.log('檢查兩遍密碼') // debugger if (this.password == '') { this.password_message = '密碼不能為空' this.password_error = true return false } if (this.password != this.password2) { this.password_message = '兩遍密碼不一致' this.password_error = true return false } if (this.password.length < 6) { this.password_message = '密碼長度不能小於6位' this.password_error = true return false } this.password_message = '' this.password_error = false },