regex - Regular Expression With String Contain Digit With WildCard/Min,MaxLength In Javascript -
i new javascript regular expressions. trying create regex on string may contain digit.
scenario following:<
the string may contain *
either before or after or both not in middle.
the string length minimum of 2 characters , maximum of 12 characters (not counting *
).
input string example:
ab1542378522 ac6546457869 oa6546457869
other valid strings are:
*154* *c6* ab* ab154237* *2378522 *c654645 *645 *ab* *ac6546457869* oa*
invalid strings:
*15*4 *15*4* *a*b15*42*37*
only *
wildcard supported, no other special character allowed in input. example in above input string ab
, ac
, oa
valid first 2 character not aa
, ax
, os
... follow 10 digits @ max.
i unable create such regex covers above use-cases. code getting exhausted if else branching. if find answer post in comment. make comment confusion.
try use pattern:
/^\*?(?=[^*]{2})[a-z]{0,2}[0-9]{0,10}\*?$/
pattern explanation:
^ begining of string \*? optional * (?=[^*]{2}) check if @ least 2 characters not * follows [a-z]{0,2} between 0 , 2 letters [0-9]{0,10} between 0 , 10 digits \*? optional * $ end of string
Comments
Post a Comment