2013-10-15 46 views
0

好吧,我有以下jQuery代码,但我不知道我错了。我试图验证一个单独的文本输入。有人可以改进代码。 :)
表单输入文本与JQUERY验证失败

$(document).ready(function(){ 
var count = 0; 

$(cellphone).keyup(function(){ 

    var regEx =/[1-9 ]/; 
    count = count + 1; 
    var Str = $('#cellphone').val(); 

if(!regEx.test(Str)){ 
    $("#msg").text("Phone number format invalid"); 
    } 

if(count>11){ 

    //alert("Cellphone number invalid, please check"); 

    $("#msg").text("Phone number Invalid"); 
    } 

    }); 
}); 
+0

在线路号码4应该是'#手机' –

回答

0
Dude, Don't go for the hardest thing 
Use Validate Plugin for Validation 
Example: 
$("#myform").validate({ 
rules: { 
'field_name': { 
    required: true, 
minlength:10 
    maxlength: 10 
}, 
messages: { 
'field_name': { 
    required: 'Required', 
    minlength: 'Length is Lesser than 10', 
    maxlength: 'Length exceeds Greater than 10' 
} 

} }); Plugin

+0

非常感谢你的工作。我对图书馆很陌生,所以我仍然发现我的脚。谢谢Nanda –