Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
regex expression in js

i want to ask how should i modify this expression /^(\+?266)(22|28|57|58|59|27|52)\d{6}$/ so that the evaluated value always start with +266 and 2 digits after that should be 22 or 28 or 57 or 58 or 59 or 27 or 52 followed by 6 random numbers

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

It looks like you're almost good to go, except it's not clear why the first ? is in there if you always want to start with +266, also you wrote 37 in the question but have 27 in the regex you included.

Also you didn't say anything about needing capturing groups so you can do away with the first set of brackets. The second set of brackets is required for the 'or' (|) but you can include ?: to make it non-capturing.

Give this a try:

/^\+266(?:22|28|57|58|59|27|52)\d{6}$/gm

You can see it working here:

https://regex101.com/r/ZQqthS/1

about 4 years ago · Juan Pablo Isaza Report

0

Your original regex should basically work. I was about to write the same comments as @Ljdyer, but as he already mentioned it I can save my breath.

In my regexp I used a few character classes, like [28], to shorten it, but that is optional.

const rx=/^\+266(?:2[28]|5[2789]|37)\d{6}$/;

console.log(["+26628123456","+26657763883",
 "+26638123456","+266591234567"]
.map(s=>s.match(rx)));
// the first two will match, the others won't

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!