让HTML5的输入模式属性忽略大小写 [英] Have HTML5's a inputs pattern attribute ignore case

查看:204
本文介绍了让HTML5的输入模式属性忽略大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要让HTML的输入元素模式忽略值的情况,

就像正则表达式是/ [az] * /我可以让它匹配所有大写字母吗? >
(我知道我可以做/ [a-zA-Z] * /,但这只是一个例子。)

解决方案我不认为这是可能的。


  1. 关于<输入模式> [ 1 < a>, 2 ]指定




    • 该模式使用ECMAScript(即Javascript)的正则表达式风格


    • p>它是通过全局,ignoreCase和多行标志 禁用 编译的。
    • >
    • 在Javascript中,使正则表达式忽略大小写的唯一方法是在外部设置修饰符( /.../我)。不支持PCRE语法(?i)




    • 因此,模式始终区分大小写和 [a-zA-Z] * (即使正则表达式本身明确区分大小写)是以不区分大小写的方式匹配模式的唯一方法。


      I need to have HTML's input elements pattern ignore the case of the value,
      like have if the regex is /[a-z]*/ could I get it to match all uppercase letters too?
      (I know I could just do /[a-zA-Z]*/, but that was an example.)

      解决方案

      I don't think it is possible.

      1. The specification on <input pattern> [1,2] specifies that

        • the pattern uses the ECMAScript (i.e. Javascript) flavor of regex

        • it is compiled "with the global, ignoreCase, and multiline flags disabled"

      2. In Javascript, the only way to make a regex ignore case is to set the modifier externally (/.../i). The PCRE syntax (?i) is not supported.

      Therefore, the pattern is always case-sensitive and [a-zA-Z]* (i.e. making the regex itself explicitly case insensitive) is the only way to match the pattern in a case-insensitive way.

      这篇关于让HTML5的输入模式属性忽略大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆