I am using HTML5 \'pattern\' attribute with \'required\' for validation of input boxes. HTML5\'s required attribute works but it can accept spaces and tabs which is not good
<form action="demo.php">
<input id="name" type="text" pattern="^((?:\s*[A-Za-z]\s*){6,})$">
<input type="submit">
</form>
this will work for your case .. its exacly how you want it. i have set limit of character is from 6 to 40..
I managed a silly hack that does what you asked:
<input type="text" name="name" class="form-control" placeholder="Your Full Name" pattern="\s*(\S\s*){6,}" title="Name should have at least 6 characters." required="" />
There must be 6 non-space characters for this to pass. so "asdfgh", " abc def " will work, but "abc de" fails.
It DOES NOT work for your comment about "there's a space after Anthony" but as Anthony contains 6 characters, then it's fine? If not, can you clarify further in the question.
To explain how it works:
\S
followed by "none-or-more space characters" \s*
(pattern){6,}
i.e. (\S\s*){6,}
\s*
If you want to limit the characters allowed to Alpha only, change the \S
to [A-Za-z]
.
Yes, it's a hack IMO as it will be hell to parse internally on long strings. But does the job. You might want to mix with maxlength
to limit that as well?