10 examples of 'validate mobile number in javascript' in JavaScript

Every line of 'validate mobile number in javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
7function checkMobile(phone_val){
8 var pattern=/(^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$)|(^0{0,1}1[3|4|5|6|7|8|9][0-9]{9}$)/;
9 return pattern.test(phone_val);
10}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

40function isValidPhone(value) {
41 return /^[0-9]+$/ig.test(value)
42}
269static phone(value) {
270 var reg = /^((\d{10,11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/;
271 return reg.test(value);
272}
21export function isValidLength(phone: string): boolean {
22 return phone.length >= PHONE_MIN_LENGTH && phone.length <= PHONE_MAX_LENGTH;
23}
790function isPhoneNumber(number) {
791 var regex = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
792 return regex.test(number);
793}
52mobile() {
53 return !/^1[345789]\d{9}$/.test(this.value) && `请输入11位的手机号码`;
54}
28export function looksValid(phoneNumber) {
29 return PHONE_NUMBER_REGEXP.test(phoneNumber);
30}
157function isPhone(str) {
158 return /^(\+\d\d)?1\d{10}$/.test(str);
159}
28export function phoneValidator(rule, value, callback) {
29 const INVALID_PHONE_MSG = 'Número de telefone inválido';
30 const PHONE_REGEX = /^\([0-9]*\)\s*[0-9]*\s*-*\s*[0-9]*/i;
31
32 if (!rule.required && !value) {
33 callback();
34 }
35
36 if (PHONE_REGEX.test(value)) {
37 callback();
38 } else {
39 callback(INVALID_PHONE_MSG);
40 }
41}
9static isValid(control: FormControl): any {
10 let number = control.value;
11 let phoneProto;
12 if (number == null) {
13 return {
14 empty: true
15 };
16 }
17
18 let countryCode = 'US';
19 if (number.charAt(0) === '+') {
20 countryCode = 'ZZ';
21 }
22
23 try {
24 phoneProto = phoneUtil.parse(number, countryCode);
25 } catch (e) {
26 return {
27 'not a phone nubmer': true
28 };
29 }
30
31 let isValid = phoneUtil.isValidNumber(phoneProto);
32
33 if (!isValid) {
34 return {
35 'not valid': true
36 };
37 }
38
39 return null;
40}

Related snippets