简体   繁体   English

使用HTML 5和pattern属性时,如何将输入内容限制为仅英文字母?

[英]How do I restrict my input to only the English alphabet when using HTML 5 and the pattern attribute?

Everytime I try to validate a pattern in an input tag (text), so far in FireFox and Chrome, it does not work. 到目前为止,每次我尝试验证input标签(文本)中的模式时,到目前为止,在FireFox和Chrome中,该模式均无效。 It does not work on any page. 它不适用于任何页面。 Neither the restriction on the character input, nor the number of characters works. 字符输入的限制或字符数都不起作用。 I know I can use JavaScript. 我知道我可以使用JavaScript。 I want to make it work with HTML 5, using the pattern attribute. 我想使用pattern属性使其与HTML 5一起使用。 Am I doing it wrong? 我做错了吗? Was it removed from the standard? 它从标准中删除了吗?

Example, 例,

http://www.wufoo.com/html5/attributes/10-pattern.html http://www.w3schools.com/tags/att_input_pattern.asp http://www.wufoo.com/html5/attributes/10-pattern.html http://www.w3schools.com/tags/att_input_pattern.asp

or my own, 还是我自己的

 <form id="request" action="mypage.php" method="POST"> <fieldset> <legend>Request Form</legend> <label for="first-name">First Name</label> <input type="text" placeholder="First Name" name="first-name" id="first-name" pattern="^/[A-Za-z]{3}/$" title="Enter First Name" size="20"> </fieldset> </form> 

I have also tried, 我也尝试过

pattern="[A-Za-z]{3}"
pattern="[A-Z][a-z]{20}"
pattern="^[A-Za-z]{3}$"

and others. 和别的。

I got it. 我知道了。 My problem was I expected it to die before I hit submit. 我的问题是我希望它在我提交之前就死掉。 I forgot you it doesn't react like JavaScript and the keyevent. 我忘记了它不会像JavaScript和keyevent那样反应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM