开发者

run $.ajax() when end typed with format specified. how is it?

i want, when user typed, 0000/00/00(it is format date) after the end of typing run anything(example: AJAX CALL), how is it?

like:
if user typed: 2011/05/04 -> run: $.ajax()...
if user typed: 2011/05 -> not run: $.ajax()...
...

only thing for run $.ajax() is true type 开发者_运维技巧this format 0000/00/00.

I hope you understand my purpose.

With respect.


HTML:

<input type="text" name="datefield" onchange="validateField(this)" />

JS:

function validateField() {
   var val = this.value;
   if (val.length < 10) {
      return;
   }
   if (!val.match(/\d\d\d\d\/\d\d\/\d\d/)) {
      return;
   }
   ... do ajax call here
}


$("inputTextBoxSelector").keyup(function(e){
  if($(this).val().match(/\d\d\d\d\/\d\d\/\d\d/){
    $.ajax(....);
    return false;
  }
})


You can do...

$('input').change(function(e) {
  var val = $(this).val();
  if ( val.length == 10 ) {
    if( val.match(/^\d{4}\/\d{2}\/\d{2}$/) ) {
      $.ajax();
    }
  }
});

You can also try keyup instead of change.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜