javascript - 电子邮件正则表达式中缺少验证
问题描述
所以,这是我的代码:
<p>A form with a password field that must contain 8 or more characters that are of at least one number, and one uppercase and lowercase letter:</p>
<form action="">
Password: <input type="text" name="pw" pattern="[A-Za-z0-9._%+'-\]+@[a-z0-9.-]+\.[a-z]{2,4}$" required title="Must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters">
<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.</p>
为什么它允许
- 测试网
- @text.com
我加@
了一个加号,在它之前有一个或多个字符。但它似乎不起作用
解决方案
您的模式有问题,您正在转义第一个]
char :
"[A-Za-z0-9._%+'-\]+@[a-z0-9.-]+\.[a-z]{2,4}$"
^
here
\
使用另一个转义它\
: "[A-Za-z0-9._%+'-\\]+@[a-z0-9.-]+\.[a-z]{2,4}$"
它应该可以工作
ps:你说你不能使用type="email"
bu 你可以看到它的文档,有使用的正则表达式
推荐阅读
- vue.js - 检查 VTextField 的验证
- marklogic - 在marklogic中将来自两个不同服务器的相同数据库组合到第三个服务器
- javascript - 为什么控制台说不能设置null的属性
- javascript - 如何停止递归函数?
- python - 如何使用单个命令使所有 Voluptuous 字段都需要?
- ios - 有没有办法让枚举返回 UIViewController
- java - 捕获 ConstraintViolationException - 不起作用
- python - Tkinter 中的线程自动启动
- java - 在云手表中禁用 Azure 服务总线打印日志
- python - 努力创建正确的正则表达式