How can I match bangladeshi phone number using RegExp in javascript?

3673 views javascript
3

this following expression is working for any 11 digits phone number. But I want the first three digit to be specific operator code like (017, 016, 018, 019). And rest of the others can be any digits.

/^([\d]{3})*([\d]{8})$/

answered question

1 Answer

11

You may use an alternation here:

/^(01[6789])(\d{8})$/

Code sample:

console.log(/^(01[6789])(\d{8})$/.test('01612345678')); // pass
console.log(/^(01[6789])(\d{8})$/.test('01912345678')); // pass
console.log(/^(01[6789])(\d{8})$/.test('12312345678')); // fail

posted this

Have an answer?

JD

Please login first before posting an answer.