简体   繁体   English

使用输入的正则表达式进行表单验证

[英]Form validation with regular expression on input

I have this form and I want to enter minimum 3 chars to input area. 我有此表格,我想输入至少3个字符。

<form class="navbar-search pull-left" method="GET" action="xx.php">
    <input pattern=".{3,}" title="Enter min 3 chars" name="q" type="text" class="search-query span3" data-provide="typeahead" placeholder="Search..." />
 </form>

This is working when I enter less than 3 chars but greater than 0 char. 当我输入少于3个字符但大于0个字符时,此方法有效。 But if I press enter button directly when input area active there is not any notification and form going its direction. 但是,如果我在输入区域处于活动状态时直接按回车按钮,则不会有任何通知和表格向其方向移动。 I want to handle this. 我要处理这个。 How? 怎么样? Thanks. 谢谢。

You are missing the required attribute. 您缺少required属性。

<form class="navbar-search pull-left" method="GET" action="xx.php">
<input pattern=".{3,}" title="Enter min 3 chars" name="q" type="text" 
class="search-query span3" data-provide="typeahead" 
placeholder="Search..." required/>
</form>

Fiddle here . 在这里摆弄

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

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