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

Character limit in a regular expression Javascript

Regular expression requirements:

  • from 3 to 5 characters,

  • at least one capital letter,

    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

  • and at least one number.

My expression now looks like this.
The character limit does not work.

/((?=.*[A-Z])(?=.*\d)){3,5}/

>Solution :

{3,5} has to be after a pattern that matches something. You put it after lookaheads, which don’t match anything by themselves. Put a . before it to match a character. And you also need to anchor the regexp so it will match the entire input, not just part of it.

/((?=.*[A-Z])(?=.*\d))^.{3,5}$/
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