自动完成的JQUERY验证

| 当有人开始输入项目编号时,我有一个自动完成的文本框。这项工作正常,但是现在我想验证一下,如果他们只是输入一个数字,而不是从列表中选择一个数字,则表明它是一项工作。这是我具有的自动完成代码,文本框的ID为projectnum。
    $( \'[name=\"projectnum\"]\' ).autocomplete({
        source: \"job_validate.php\",
        minLength: 3

    });
    
已邀请:
您可以使用remote属性。这将检查表单的提交和文本框的公开模糊,以验证作业是否有效。 http://docs.jquery.com/Plugins/Validation/Methods/remote
$(\"#yourForm\").validate({
  rules: {
    projectnum: {
      required: true,
      remote: \"job_validate.php\"
    }
  }
});
    
如果您使用的是jQuery UI自动完成功能,则可以使用演示页面上的组合框之类的东西。它使用自动完成功能,但是您只能在列表中选择一个值。 http://jqueryui.com/demos/autocomplete/#combobox 这使用页面本地的源,而不是对服务器的ajax调用。     
这将只允许数字左,右:
        $(\"#field_id\").keydown(function (event) {
            if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)) // 0-9 or numpad 0-9
            {
                // check textbox value now and tab over if necessary
            }
            else if (event.keyCode != 8 && event.keyCode != 46 && event.keyCode != 37 && event.keyCode != 39) // not esc, del, left or right
            {
                event.preventDefault();
            }
            // else the key should be handled normally
        });
取自http://snipt.net/GerryEng/jquery-making-textfield-only-accept-numeric-values     

要回复问题请先登录注册