Optionaltext: string | null
The text to check
The ISO alpha-2 country code to validate via libphonenumber-js,
or a regex / regex pattern for mobile numbers (defaults to China)
whether the given text is a valid mobile phone number
isMobile(undefined); // false
isMobile('13812345678'); // true
isMobile('+8613812345678'); // true, 带国家码
isMobile('+86-13812345678'); // true, 带国家码与连字符
isMobile('12345678901'); // false
isMobile('0086-13812345678'); // false, 国际拨号前缀
isMobile('2125551234', 'US'); // true, 美国(libphonenumber-js 校验)
isMobile('2125551234', '^[2-9]\\d{2}[2-9]\\d{6}$'); // true, 美国(正则)
isMobile('2125551234', /^[2-9]\d{2}[2-9]\d{6}$/); // true, 美国(正则)
isMobile('1125551234', /^[2-9]\d{2}[2-9]\d{6}$/); // false, 区号不能以 1 开头
Returns whether the given text is a valid mobile phone number
The
alphaOrPatternargument accepts two kinds of values:CN,US), in which case the number is validated throughlibphonenumber-jsagainst that country;