LWM

java中

//        正则表达式验证身份证
        String idcard="/(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)/";
        boolean idcardB=testIdcard.matches(idcard);
//        验证电话号
        String phone="(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}";
        boolean phoneB=testPhone.matches(phone);
//        验证邮箱
        String mail="(\\w{3,10}\\.)*\\w+@\\w+(\\.\\w{2,3})*\\.\\w{2,3}";
        boolean mailB=testMail.matches(mail);

vue中

// idcard失去焦点事件
            idcardBlur:function(){
                let idcard=/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                if(!idcard.test(this.person_info.cardId)){
                    this.$message("身份证号不合法,请重新输入!");
                    this.person_info.cardId='';
                }
            },
            // phone失去焦点事件
            phoneBlur: function() {
                let phone = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
                if (!phone.test(this.person_info.telephone)) {
                    this.$message("电话号不合法,请重新输入!");
                    this.person_info.telephone = '';
                }
            },
            // mail失去焦点事件
            mailBlur: function() {
                let mail = /^([a-zA-Z\d][\w-]{2,})@(\w{2,})\.([a-z]{2,})(\.[a-z]{2,})?$/;
                if (!mail.test(this.person_info.mail)) {
                    this.$message("邮箱不合法,请重新输入!");
                    this.person_info.mail = '';
                }
            },

 

posted on 2023-02-23 18:46  Lwmm  阅读(23)  评论(0编辑  收藏  举报