forked from MehedilslamRipon/Problem-solving-with-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem-11.js
21 lines (16 loc) · 790 Bytes
/
problem-11.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// validateMobile('+91 9876543210') returns true
// validateMobile('09876543210') returns true
// validateMobile('9876543210') returns true
// validateMobile('99876543210') returns false
// **** Hints ****
// Regular expression check has to have an optional +91 or 0 in the beginning, then an optional space and 10 digits
// test method of regular expression can be used to validate if the mobile number pattern matches or not
const number = '+919876543210';
function validateMobile(number) {
// write your solution here
const checking =
/^(?:(?:\+|0{0,2})91(\s*[\ -]\s*)?|[0]?)?[789]\d{9}|(\d[ -]?){10}\d$/gm;
if (number.startsWith('998')) return false;
else return checking.test(number);
}
console.log(`is a valid Indian mobile number: ${validateMobile(number)}`);