首页 文章

jQuery正则表达式输入掩码在IE 7中不起作用

提问于
浏览
0

我正在使用https://github.com/RobinHerbots/jquery.inputmask的jQuery输入掩码,在Firefox,Chrome或IE 8中没有问题 .

但是,当我使用以下正则表达式输入掩码时,IE 7仅显示数据源中的第一个字符 . 我知道数据存在,因为如果我将文档模式从IE 7标准切换到IE 8标准或更高,则数据立即可见 .

有没有办法让正则表达式输入掩码显示IE 7中的所有数据?

$(".alpha").inputmask('Regex', { regex: "[a-zA-Z ]+" }); // Limits entry to letters and space character
$(".name").inputmask('Regex', { regex: "[a-zA-Z-`' ]+" }); // Limits entry to letters, -, `, ' and space character 
$(".alphanumeric").inputmask('Regex', { regex: "[a-zA-Z0-9 ]+" }); // Limits entry to letters, numbers and space character

1 回答

  • 1

    看来这与此处记录的IE 7前瞻错误相关http://blog.stevenlevithan.com/archives/regex-lookahead-bug将上述正则表达式更改为已解决问题(替换为{n,m})

    // Due to lookahead bug in IE 7, used {n,m} instead of just +
    $(".alpha").inputmask('Regex', { regex: "[a-zA-Z ]{1,50}" }); // Limits entry to letters and space character
    $(".name").inputmask('Regex', { regex: "[a-zA-Z-`' ]{1,50}" }); // Limits entry to letters, -, `, ' and space character 
    $(".alphanumeric").inputmask('Regex', { regex: "[a-zA-Z0-9 ]{1,50}" }); // Limits entry to letters, numbers and space character
    

相关问题