javascript - Regex: Minimum 13 characters and WITHIN 13 characters maximum 3 characters -


i need expression validates, this:

1234-567.890-123

  • min 13 numbers
  • max 3 special characters ("-" , .) <-- no matter where

my solution [0-9]{13,}[-\.]{0,3}can't work validates:

1234567890123.-.

if ordering of characters in string not matters, can use

^(?=(?:[\d.-]){13,}$)(?=(?:\d*\d){13,})(?!(?:[^.-]*[.-]){4}).*$ 

regex breakdown

^ #starting of string  (?=(?:[\d.-]){13,}$) #lookahead sees string contains digits, . , -  (?=(?:\d*\d){13,}) #lookahead match 13 digits  (?!(?:[^.-]*[.-]){4}) #looahead number of . , - not equal 4  .* $ 

middle part

(?= #lookahead    (?:\d*\d) #match non-digits , digit.    {13,} #repeat @ least 13 times.in simple words, matching @ least 13 digits. ) 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -