HTML5 输入模式搜索报价 [英] HTML5 input pattern search for quote
问题描述
我需要针对此正则表达式测试输入字段 (<input type="text"/>
):
I need to test an input field (<input type="text" />
) against this regex:
[^'"]+
这显然不是一件容易的事,因为我不能在属性中使用 "
.使用 quot 实体似乎不起作用,因为它被正则表达式引擎逐字解释.
This obviously is no easy task as I cannot use "
inside the attribute. Using the quot entity does not seem to work as it gets interpreted literally by the regex engine.
我怎样才能做到这一点?
How can I accomplish this?
推荐答案
HTML5 @pattern 属性正则表达式基于 JavaScript 正则表达式,因此您可以使用 十六进制表示法 或 unicode 表示法 就像在 JavaScript 中一样:
The HTML5 @pattern attribute regex is based on JavaScript regex, so you can use hexadecimal notation or unicode notation for that char as you would in JavaScript:
" = x22 OR u0022
' = x27 OR u0027
以便您可以轻松使用
pattern="[^'x22]+"
多田!不涉及 JavaScript 库!;)
TADA! No JavaScript libraries involved! ;)
这篇关于HTML5 输入模式搜索报价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!