论坛首页 Web前端技术论坛

jquery验证手机号码和邮箱地址例子

浏览 4175 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2012-05-12  
//jquery验证邮箱
    function checkSubmitEmail(){
       if($("#email").val()==""){
    $("#confirmMsg").html("<font color='red'>邮箱地址不能为空!</font>");
    $("#email").focus();
    return false;
   }
   if(!$("#email").val().match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)){
    $("#confirmMsg").html("<font color='red'>邮箱格式不正确!请重新输入!</font>");
    $("#email").focus();
    return false;
   }
   return true;
    }
   
    //jquery验证手机号码
    function checkSubmitMobil(){
       if($("#mobil").val()==""){
    $("#moileMsg").html("<font color='red'>手机号码不能为空!</font>");
    $("#mobil").focus();
    return false;
   }

   if(!$("#mobil").val().match(/^1[3|4|5|8][0-9]\d{4,8}$/)){
    $("#moileMsg").html("<font color='red'>手机号码格式不正确!请重新输入!</font>");
    $("#mobil").focus();
    return false;
   }
   return true;
    }
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics