zoukankan      html  css  js  c++  java
  • input验证 正则 代码示例

    $(function(){    
        var name = $(".basic-information-item #name");
        var emil = $(".basic-information-item #emil");
        var btn = $(".basic-information-item #btn");
        var regMail = /[a-zA-Z0-9]{1,10}@[a-zA-Z0-9]{1,5}.[a-zA-Z0-9]{1,5}/;
        var patrn=/^[a-zA-Z0-9u4e00-u9fa5]*$/;
        function checkname(){
            if(!patrn.test(name.val())){
                name.siblings('#ckerror').show().html("<i class='iconfont'>�</i> 请输入数字、汉字、字母");
                return false;
            }else if(name.val().length < 2){
                name.siblings('#ckerror').show().html("<i class='iconfont'>�</i> 至少输入2个字符");
                return false;
            }else{
                name.siblings('#ckerror').hide();
            }
        }
        function checkemail(){
            if (!regMail.test(emil.val())){
                emil.siblings('#ckerror').show().html("<i class='iconfont'>�</i> 请输入正确的邮箱");
                return false;
            }
            else {
                emil.siblings('#ckerror').hide();
            }
        }
        name.blur(function(){
            return checkname();
        });
        name.focus(function(){
            $(this).siblings('#ckerror').hide();
        });
        emil.blur(function(){
            return checkemail();
        });
        emil.focus(function(){
            $(this).siblings('#ckerror').hide();
        });
        btn.on('click',  function() {
            if(!patrn.test(name.val())){
                name.siblings('#ckerror').show().html("<i class='iconfont'>�</i> 请输入数字、汉字、字母");
                return false;
            }else if(name.val().length < 2){
                name.siblings('#ckerror').show().html("<i class='iconfont'>�</i> 至少输入2个字符");
                return false;
            }else{
                name.siblings('#ckerror').hide();
            }
            if(!regMail.test(emil.val())){
                emil.siblings('#ckerror').show().html("<i class='iconfont'>�</i> 请输入正确的邮箱");
                return false;
            }
            else {
                emil.siblings('#ckerror').hide();
            }
            //return true;
            document.myform.submit();
    		//$("#myform").submit();
        });
    });
    

    验证昵称,邮箱,判断不全。。

  • 相关阅读:
    一个弹框表单复用create,edit表单操作
    数组去重,防抖节流,渲染几万条数据不卡页面,32个手撕JS,彻底摆脱初级前端
    解决vue表单回显数据无法修改的问题
    正则
    将UTC时间转换为当地的时间
    Vue页面上实时显示当前时间,每秒更新
    互联网协议
    记录:批量重命名文件夹下的文件
    IdentityServer4 无法登录,一直跳转登录界面
    同解与等价
  • 原文地址:https://www.cnblogs.com/luoluo8/p/5550057.html
Copyright © 2011-2022 走看看