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

Regex for a promo code that has the following rules

I need to build a regex that have the following:

Rules to be applied:

  • exactly 14 characters
  • only letters (latin characters) and numbers
  • at least 3 letters

Regex still confuses me so I am struggling to get the correct output. I want to use it with swift and swiftui in an app I am making

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

(?=(.*[a-zA-Z]){3,}([0-9]){0,}){14,14}$

I tried this. But I know it is not the way

>Solution :

You need to use

^(?=(?:[0-9]*[a-zA-Z]){3})[a-zA-Z0-9]{14}$

Details

  • ^ – start of string
  • (?=(?:[0-9]*[a-zA-Z]){3}) – at least three repeations of a letter after any zero or more digits sequence required
  • [a-zA-Z0-9]{14} – fourteen letters/digits
  • $ – end of string.

See the regex demo.

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