HTML5表单模式/验证 [英] HTML5 Form Pattern / Validation
问题描述
我试图想出一个HTML5表单的有效模式。我想允许所有上面&小写字母,空格,数字和符号/ \ @#$%& 。
我尝试了几种不同的格式,但我没有任何运气。
到目前为止我有:
地址:< input type =textname =Addresssize =25pattern = [a-zA-Z0-9] {2,35}]title =标题required />
这是我用w3schools测试页建立的一个例子:
$ b
<!DOCTYPE html>< html>< body><<< ; form onsubmit =getElementById('s')。innerHTML = getElementById('i').value; return false;>国家代码:< input id =itype =textname =country_codepattern =([a-zA-Z0-9] | | / | \\ | @ |#| \ $ |%|&)+title =三字母国家代码> < input type =submit>< / form>< p>提交值:< span id =s>
注意:Internet Explorer 9及更早版本或Safari中不支持输入标记的模式属性。
$ b $您可以使用它在进行自己的测试http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_pattern
I am trying to come up with a valid pattern for an HTML5 form. I would like to allow all upper & lower case letters, spaces, numbers, and the symbols / \ @ # $ % & .
I've tried a couple different formats but I haven't had any luck.
So far I have:
Address: <input type="text" name="Address" size="25" pattern="[a-zA-Z0-9 ]{2,35}]" title="Title" required/>
This is an example I built with w3schools test page:
<!DOCTYPE html>
<html>
<body>
<form onsubmit="getElementById('s').innerHTML=getElementById('i').value;return false;">
Country code: <input id="i" type="text" name="country_code" pattern="([a-zA-Z0-9]| |/|\\|@|#|\$|%|&)+" title="Three letter country code">
<input type="submit">
</form>
<p>Submitted value: <span id="s">
Note: The pattern attribute of the input tag is not supported in Internet Explorer 9 and earlier versions, or in Safari.
You can use it to make your own tests at http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_pattern
这篇关于HTML5表单模式/验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!