jQuery.autocomplete:如何有条件地使用minLength?

jQuery.autocomplete:如何有条件地使用minLength?,jquery,Jquery,在邮政编码的html输入上,我附加了jQuery.autocomplete,并用以下方式屏蔽: <input type="text" name="PostCode" id="PostCode" size="10" value="<% = vPostCode %>"> <script type="text/javascript"> $(function() { $("#PostCode").mask("999 99"); $("#PostCod

在邮政编码的html输入上,我附加了jQuery.autocomplete,并用以下方式屏蔽:

<input type="text" name="PostCode" id="PostCode" size="10" value="<% = vPostCode %>">
<script type="text/javascript">
$(function() {
    $("#PostCode").mask("999 99");

    $("#PostCode").autocomplete({
        source: function( request, response ) {
            $.ajax({
                url: "./ajax.asp"
                , dataType: "jsonp"
                , data: {
                    ajax: "1",
                    action: "getPC",
                    maxRows: 10,
                    contains: request.term
                }
                , success: function( data ) {
                    response( $.map( data.PC, function( item ) {
                        return {
                            label: item.pCode + ' : ' + item.City + ' : ' + item.Region
                            , value: item.pCode
                        }
                    }));
                }
                , contentType: "application/x-www-form-urlencoded;charset=1253"
            });
        }
        , select: function( event, ui ) {
            $("#PostCode").val(ui.item.zip);
        }
        , minLength: 2
        , selectFirst: true
        , delay: 200
    });
});
</script>
当光标输入空的输入id=邮政编码时,会出现问题,它由3个下划线、空格和2个下划线填充,这是正常的,因为存在掩码。 但是由于minLength:2,它会导致自动完成工作

我如何告诉minLength part忽略____;序列,因为只有数值是有效的,或者换句话说,如何仅在用户输入数值时触发autocomplete,而在未输入任何值时触发ignore

我使用的是jquery1.71和jQuery.maskedinput 1.2.2


谢谢

尝试替换$request.term.replace_uu,,以获取实际文本

我在这里发现了一个类似的问题

正则表达式似乎包含了您需要的所有内容。最小值2、数字、掩码等

jQuery.validator.addMethod("zipcodeUS", function(value, element) {
return this.optional(element) || /\d{5}-\d{4}$|^\d{5}$/.test(value);
}, "The specified US ZIP Code is invalid");
这一个有一个范围是有用的

jQuery.validator.addMethod("ziprange", function(value, element) {
   return this.optional(element) || /^90[2-5]\d\{2\}-\d{4}$/.test(value);
   }, "Your ZIP-code must be in the range 902xx-xxxx to 905-xx-xxxx");

然后,您可以将这些规则与validate方法结合使用,并调用autocomplete。

thanx进行研究,但这不是我问题的答案。我只想忽略掩码生成的字符,因为它们会导致自动完成时的ajax调用!