HTML5 Form Pattern / Validation

余生长醉 提交于 2019-11-30 19:01:43

问题


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/>

回答1:


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



来源:https://stackoverflow.com/questions/17353792/html5-form-pattern-validation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!