Reputation: 203
I want to use regex specifically! to check if a mobile number contains 9 or more digits. I am a little unsure as to how to format this exactly.
I want to check inside an if statement like the below
if(mob >= (.{9})
This is clearly not correct, any help would be great
Upvotes: 0
Views: 46
Reputation: 36594
You need to check of numbers not for all the characters. And also use test()
to check if string matches regex or not.
const testMob = str => /^\+?[0-9]{9,}$/.test(str);
console.log(testMob('+123456789')) //true
console.log(testMob('+1234567890')) //true
console.log(testMob('+133333')) //false
Upvotes: 0
Reputation: 522712
Use test
with the regex pattern ^\+?[0-9]{9,}$
:
var number = "+123456789";
if (/^\+?[0-9]{9,}$/.test(number)) {
console.log("MATCH");
}
Upvotes: 1