HTML5 输入模式搜索报价

发布于 2025-01-07 06:08:13 字数 184 浏览 5 评论 0原文

我需要针对此正则表达式测试输入字段 ():

[^'"]+

这显然不是一件容易的任务,因为我无法在内部使用 "使用 quot 实体似乎不起作用,因为它是由正则表达式引擎逐字解释的

I need to test an input field (<input type="text" />) against this regex:

[^'"]+

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一绘本一梦想 2025-01-14 06:08:13

HTML5 @pattern 属性正则表达式基于 JavaScript 正则表达式,因此您可以像在 JavaScript 中一样为该字符使用十六进制表示法unicode 表示法

" = \x22 OR \u0022
' = \x27 OR \u0027

以便您可以轻松使用

pattern="[^'\x22]+"

田田!不涉及 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

So that you can easily use

pattern="[^'\x22]+"

TADA! No JavaScript libraries involved! ;)

海螺姑娘 2025-01-14 06:08:13

您可以使用十六进制表示法代替 '"

pattern="[^'\x22]+"

<form action="#">
<input type="text" title="no quotes!" pattern="[^'\x22]+">
<button type="submit">submit</button>
</form>

You can use Hexadecimal notation instead of ' or ".

pattern="[^'\x22]+"

<form action="#">
<input type="text" title="no quotes!" pattern="[^'\x22]+">
<button type="submit">submit</button>
</form>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文