浏览器用于HTML5输入type = url的正则表达式是什么? [英] What regular expression does a browsers use for HTML5 input type=url?

查看:164
本文介绍了浏览器用于HTML5输入type = url的正则表达式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究HTML5输入模式polyfill,我正在尝试在JavaScript中验证输入类型= url,就像浏览器(Chrome)一样,但找不到有关JavaScript或PERL兼容正则表达式的任何文档。因为它是一个polyfill,我不特别介意它是否完全匹配所有URL(这是不可能的),而是它模仿浏览器的工作方式。

I'm working on a HTML5 input pattern polyfill and I'm trying to validate an input type=url in JavaScript exactly as the browser (Chrome) does but can't find any documentation on a JavaScript or PERL compatible regular expression. As it's a polyfill, I don't particularly mind if it matches all URL's exactly (which is impossible) but rather that it imitates how the browser works.

有谁知道PERL语法中相同模式的结果?

Would anyone know of an identical pattern in PERL syntax?

谢谢

推荐答案

阅读 http://www.w3中的相关规范.org / TR / html5 / forms.html#url-state-(type = url)

您的polyfill应该首先清理输入,即删除换行符并修剪字符串。句子用户代理不得允许用户插入LF(U + 000A)或CR(U + 000D)字符也可能很有趣。

Your polyfill should start with sanitizing the input, i.e. removing linebreaks and trimming the string. The sentence "User agents must not allow users to insert "LF" (U+000A) or "CR" (U+000D) characters" might also be interesting.

结果应为有效绝对网址。参考的RFC 3986 3987 将描述URL验证,关于解析网址可能也很有趣。

The results should be a valid, absolute URL. The there referenced RFCs 3986 and 3987 will be describing the URL validation, the section about parsing URLs may be as well interesting.

您的polyfill可能不仅验证URI,还可能解析相对URI 。至少,使用algortihm验证URI会更简单,而不是找到合适的正则表达式。然而,即使RFC提到了一个正则表达式,用于解析已经验证的 URI >附录B

Your polyfill might not only validate URIs, it also may resolve relative URIs. At least, validating a URI will be much simpler with an algortihm instead of finding an appropriate regexp. Yet, even the RFC mentions a regexp for parsing a already validated URI in appendix B.

这篇关于浏览器用于HTML5输入type = url的正则表达式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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