How do you specify a pattern in an input field?

html
#1

How do you specify a pattern in an input field?

1 Like
#2

In this case, we’ll specify that the username should only consist of lowercase letters; no capital letters, numbers or other special characters allowed. In addition, the username length shouldn’t be more than 15 characters.

pattern="[a-z]{1,15}"

ex. 

<form action="somefile.php">
    <input type="text" name="username" placeholder="Username" pattern="[a-z]{1,15}">
</form>

See https://webdesign.tutsplus.com/tutorials/html5-form-validation-with-the-pattern-attribute--cms-25145 for more info.

1 Like