简体   繁体   中英

Form validation with regular expression on input

I have this form and I want to enter minimum 3 chars to input area.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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