+ 2
return /^\d{5,6}(-\d{4})?$/.test(str); ?
+ 2
/(^\d{5}$)|(^\d{5}-\d{4}$)/
+ 2
/^\d{6}(-\d{4})?$/
Simple replace 5 with 6 now it will allow 6 digit
ex :
231301-2123 //pass
618464 //Pass
if u want both
u can use 5 || 6 or 5,6
/^\d{5||6}(-\d{4})?$/
/^\d{5,6}(-\d{4})?$/
+ 2
It's one of the concept taught in Sololearn itself. You can use {A,B} to specify the repeation range of a sub regex. I would like to memorize it as {N} is derived from the syntax.
https://www.sololearn.com/learn/9639/?ref=app
+ 1
https://regexr.com
This might help u