【问题标题】:Ignoring Case sensitivity for given pattern HTML忽略给定模式 HTML 的区分大小写
【发布时间】:2017-03-17 08:55:14
【问题描述】:

https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_pattern

在上面的代码中,如果我们将pattern替换为pattern="(W-([0-9]{1,3})KG)?"

预期值的格式为: “W-23KG”

我知道忽略大小写,我们必须使用 (?i)

因此,如果模式更改为 pattern="(W-([0-9]{1,3})KG)?(?i)" ,则接受以下值: “w-23Kg” “W-23KG” “W-23kg”

但是,问题在于它还接受以下值:

<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php">
  Country code: <input type="text" name="country_code" pattern="(W-([0-9]{1,3})KG)?" title="Three letter country code">
  <input type="submit">
</form>

<p><strong>Note:</strong> The pattern attribute of the input tag is not supported in Internet Explorer 9 and earlier versions, or in Safari.</p>

</body>
</html>

"w-23kgW-23kgabcdefgh"

【问题讨论】:

标签: javascript html


【解决方案1】:

没有通用的方法可以忽略模式属性中的大小写,但在您的情况下,您可以使用 [Ww][Kk] 等使各个字母不区分大小写。

<input type="text" name="country_code" 
       pattern="([wW]-([0-9]{1,3})[kK][gG])" 
       title="Three letter country code">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多