文本框验证正则表达式

只能输入数字:

<input type="text" id="e_Phone" name="e_Phone" 
                                   onkeyup="this.value=this.value.replace(/\D/g,'')"
                                   onafterpaste="this.value=this.value.replace(/\D/g,'')"
                                   onblur="checkePhone()"/>

只能输入中文汉字:

<input type="text" onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')"
    onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))"/>

只能输入英文和数字

<input type="text" onkeyup="value=value.replace(/[\W]/g,'') "
    onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">

只能输入数字,小数点,下划线:
 

<input type="text" name="price" 
    onkeyup="value=value.replace(/[^\d\._]/g,'')">

只能输入中文,英文,数字,@符号,.符号和!符号:
 

<textarea name="e_Description" id="e_Description" class="layui-textarea"
                                      onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\@\.\!]/g,'')"></textarea>

非空验证:

function checkCode() {
        var e_Code = $("#e_Code").val();//拿到input文本框值
        if (e_Code.trim().length <= 0) { //判断值长度(去空格)小于0
            layer.msg("员工编码不能为空!");  //输出提示
            return false;
        }
        return true;
    }

验证姓名文本框不能输入数字

function checkeRealName() {
        var e_RealName = $("#e_RealName").val();
        for (var i = 0; i < e_RealName.length; i++) {
            var j = e_RealName.substring(i, i + 1);
            if (j > 0) {
                layer.msg("姓名中不能包含数字!")
                return false;
            }
        }
        if (e_RealName.trim().length <= 0) {
            layer.msg("姓名不能为空!");
            return false;
        }
        return true;
    }

验证手机号文本框格式:

function checkePhone() {
        var e_Phone = $("#e_Phone").val();
        var reg = /^1[345789]\d{9}$/;

        if (reg.test(e_Phone)==false) {
            layer.msg("手机号码格式不正确,只能以13,14,15,17,18,19为开头的11位数字");
            return false;
        }


        if (e_Phone.trim().length <= 0) {
            layer.msg("员工电话不能为空!");
            return false;
        }
        return true;
    }

验证邮箱文本框格式:

function checkEmail(){
		var email = $("#email").val();
		if(email.trim().length<=0){
			$("#DivEmail").html("电子邮箱不能为空")
			return false;
		}
		if(email.indexOf("@")==-1){
			$("#DivEmail").html("电子邮箱中必须包含符合@");
			return false;
		}
		if(email.indexOf(".")==-1){
			$("#DivEmail").html("电子邮箱中必须包含符合.");
			return false;
		}
		return true;
	}

验证密码长度:

function checkPass(){
		var pass = $("#pass").val();
		if(pass.trim().length<6){
			$("#DivPwd").html("密码必须大于等于6位");
			return false;
		}
		return true;
	}

验证两次密码是否相同:

function checkrPass(){
		var pass = $("#pass"); //第一次输入的密码
		var rp = $("#rpass");  //确认密码
		if(pass.val()!=rp.val()){
			$("#DivRepwd").html("两次输入的密码不一致");
                        return false;
		}
		return true;
	}

猜你喜欢

转载自blog.csdn.net/weixin_41595700/article/details/85108278
今日推荐