How can I make sure an input field only consist of lower and uppercase letters, numbers and the characters .
and _
just in HTML. I have tried using the pattern attribute, however I am not sure whether this is correct or not:
<input
name="username"
type="text"
pattern="[a-z][A-Z][0-9][.][_]"
placeholder="Username"
/>
Thank you for your help.
Your pattern requires one character of each type, in order. If you want to match all the characters, put them in a single character class, and quantify it with *
pattern="[a-ZA-Z0-9._]*"
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.