手機和郵箱的正則表達式


//正則判斷
var phoneReg = /^1[345789]\d{9}$/; 手機號正則格式
var emailReg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/; 郵箱正則格式
phoneReg .test() 判斷test()里的手機號值是否為正則
$("#phone").blur(function () {
    if(!$(this).val()){
        phones = false;
        $(this).next().text("*此內容不能為空");
    }else {
        if(phoneReg.test($(this).val())){
            phones = true;
            $(this).next().text("");
        }else {
            phones = false;
            $(this).next().text("*手機號填寫有誤,請檢查");
        }
    }
});

$("#email").blur(function () {
    if(!$(this).val()){
        emails = false;
        $(this).next().text("*此內容不能為空");
    }else {
        if(emailReg.test($(this).val())){
            emails = true;
            $(this).next().text("");
        }else {
            emails = false;
            $(this).next().text("*郵箱格式錯誤,請檢查");
        }
    }
});

 

 

 
         
         
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM