0

我不想让邮政编码的首字母全为零。

$('#zipcode').mask("Y0000", {
  'clearIfNotMatch': true,
  'translation': {
    Y: {
      pattern: /[1-9]/
    }
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.10/jquery.mask.js"></script>

<input name="zipcode" id="zipcode" class="form-control" type="text" required>

4

1 回答 1

1

动态掩码应该有帮助:

var options =  {
  'onKeyPress': function(cep, e, field, options){
    var masks = ['00000', '0000Z'];
    mask = (cep == '0000') ? masks[1] : masks[0];
    $('#zipcode').mask(mask, options);
  },
  'clearIfNotMatch': true,
  'translation': {
      'Z': {
        pattern: /[1-9]/
      }
    }
};

$('#zipcode').mask("00000", options);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.10/jquery.mask.js"></script>

<input name="zipcode" id="zipcode" class="form-control" type="text" required>

于 2017-02-24T11:43:55.250 回答