手机获取验证码 及倒计时 正则表达式判断手机号,客户端校验

html部分代码

<van-button slot="button" size="small" type="primary" class="codeBtn" :disabled="!regShow" @click="getCode">
    <span v-show="regShow">获取验证码</span>
    <span v-show="!regShow">{{count}} s后重新获取</span>
</van-button>
export default{
    data(){
        return{
            user:{dl_name:'',dl_password:'',dl_password2:'',verificationCode:''},
            regShow: true,
            count: '',
            timer: null,
        }
    },
    methods:{
        check:function(that){
            let that=this;
            if (that.user.dl_name === "") {
                Toast('姓名不能为空');
                return false;
            }else if(that.user.dl_name.length>20){
                Toast('姓名超长');
            }else if (that.user.dl_phone=== "") {
                Toast('电话不能为空');
                return false;
            }else if (that.user.dl_password === "") {
                Toast('密码不能为空');
                return false;
            }else if (that.user.dl_password2 === "") {
                Toast('确认密码不能为空');
                return false;
            }else if(that.user.dl_password.length>6&&that.user.dl_password.length<20){
                Toast('密码长度不在6-20内');
                return false
            } else if (that.user.dl_password != that.user.dl_password2) {
                Toast('两次输入密码不同');
                return false;
            }else if (that.user.verificationCode === "") {
                Toast('验证码不能为空');
                return false;
            }
            return true;
        },
        getCode(){
            let that=this;
            let regexp1 = /^[0-9]*$/g;
            let reg=/^[1][3,4,5,7,8][0-9]{9}$/;

            if(that.user.dl_phone===""){
                Toast('电话不能为空');
                return false;
            }
            if(!regexp1.test(that.user.dl_phone)){
                Toast('电话填有额外字符');
                return false;
            }
            if(that.user.dl_phone.length!=11){
                Toast('电话位数错误');
                return false;
            }
            if(!reg.test(that.user.dl_phone)){
                Toast("电话格式不正确");
                return false;
            }
            console.log(this.user)
            this.$http.get(...)
                .then(function(response){
                    that.infoList=response.data.data
                    if (response.data.code > 399) {
                        Toast(response.data.msg);
                    }
                })
                .catch(function(err){
                    Toast(err.msg);
                });
            const TIME_COUNT = 60;
            if (!this.timer) {
                this.count = TIME_COUNT;
                this.regShow = false;
                this.timer = setInterval(() => {
                    if (this.count > 0 && this.count <= TIME_COUNT) {
                        this.count--;
                    } else {
                        this.regShow = true;
                        clearInterval(this.timer);
                        this.timer = null;
                    }
                }, 1000)
            }
        }
    }
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值