0

好的,我有以下 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");
    }

  });
});
4

1 回答 1

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'
}

} }); 插入

于 2013-10-15T14:31:33.317 回答