【问题标题】:jQuery regex inputmask does not work in IE 7jQuery 正则表达式输入掩码在 IE 7 中不起作用
【发布时间】:2014-01-03 20:24:12
【问题描述】:

我正在使用来自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

【问题讨论】:

  • 发生这种情况时,您是否在 Ie7 中遇到错误?
  • 没有错误,只是显示数据的第一个字符
  • 很抱歉你不得不支持IE7(也许是时候找一份更好的工作了???)
  • 我希望我不必支持 IE 7,但我愿意

标签: jquery regex internet-explorer internet-explorer-7 jquery-inputmask


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-20
    相关资源
    最近更新 更多