+ 2
return /^\d{5,6}(-\d{4})?$/.test(str); ?
18th Oct 2021, 11:36 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 2
/(^\d{5}$)|(^\d{5}-\d{4}$)/
18th Oct 2021, 11:13 AM
Pariket Thakur
Pariket Thakur - avatar
+ 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})?$/
18th Oct 2021, 11:36 AM
Pariket Thakur
Pariket Thakur - avatar
+ 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
18th Oct 2021, 11:42 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 1
https://regexr.com This might help u
18th Oct 2021, 11:42 AM
Pariket Thakur
Pariket Thakur - avatar