常用正則表達式

手機號碼認證:

(!/^((13\d{9})|(15[0-3,5-9]\d{8})|(14[5,7]\d{8})|(18[0,2-9]\d{8}))$/.test(this.value))


例子:

//手機號認證
        $("#phonenum").blur(function(){
            if(this.value==""||this.value.length!=11||(!/^((13\d{9})|(15[0-3,5-9]\d{8})|(14[5,7]\d{8})|(18[0,2-9]\d{8}))$/.test(this.value))){
                $(this).parent().parent().addClass("error");
                $(this).parent().siblings(".form_tip").html("手機號格式不正確");
                $(this).css("border","1px solid #900");
            }else{
                $(this).parent().parent().addClass("succeed");
                $(this).parent().siblings(".form_tip").html("輸入正確");
                $(this).css("border","1px solid #090");
            }
        }).focus(function(){
            $(this).parent().siblings(".replace_value").html("");
            $(this).parent().siblings(".form_tip").html("");
            $(this).parent().parent().removeClass("error");
            $(this).parent().parent().removeClass("succeed");
            $(this).css("border","1px solid #999");
        })


郵箱格式認證:

""&&!/.+@.+\.[a-zA-Z]{2,4}$/.test(this.value)


例子:

//郵箱認證
        $("#email").blur(function(){
            if(this.value==""||this.value!=""&&!/.+@.+\.[a-zA-Z]{2,4}$/.test(this.value)){
                $(this).parent().parent().addClass("error");
                $(this).parent().siblings(".form_tip").html("郵箱格式不正確");
                $(this).css("border","1px solid #900");
            }else{
                $(this).parent().parent().addClass("succeed");
                $(this).parent().siblings(".form_tip").html("輸入正確");
                $(this).css("border","1px solid #090");
            }
        }).focus(function(){
            $(this).parent().siblings(".replace_value").html("");
            $(this).parent().siblings(".form_tip").html("");
            $(this).parent().parent().removeClass("error");
            $(this).parent().parent().removeClass("succeed");
            $(this).css("border","1px solid #999");
        });


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章