Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check if input field can only consist of lower and uppercase letters, numbers and the characters . and _

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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._]*"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading