HTML5输入模式搜索报价 [英] HTML5 input pattern search for quote

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

问题描述

我需要对这个正则表达式测试一个输入字段(< input type =text/> ):

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.

我该如何做到这一点?

推荐答案

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

让您可以轻松使用

So that you can easily use

pattern="[^'\x22]+"

TADA!没有涉及JavaScript库!;)

TADA! No JavaScript libraries involved! ;)

这篇关于HTML5输入模式搜索报价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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