我不想让第一个字母全部为零码。
$('#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>
答案 0 :(得分: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);
&#13;
<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>
&#13;