简体   繁体   中英

Regular expression for validate multiple mobile number

What should be the Regular expression for validating multiple Indian mobile numbers which are separated by commas , like: .

+919883443344,+91-9883443344,919883443344,91-9883443344,09883443344,9883443344

That format should be acceptable.

You need to split the phones string and evaluate one by one. Try this function:

function validatePhonesString(phonesString){
    var PHONE_NUMBER_REGEX = /(?:\+?91-?\d{10})|(?:0?\d{10})(\,(?:\+?91-?\d{10})|(?:0?\d{10}))*/;
    var valid = true;
    var phones = [];
    phones = phonesString.split(',');

    for (var i = 0; i < phones.length; i++) {
            var phone = phones[i];
            if (phone === '' || !PHONE_NUMBER_REGEX.test(phone)) {
                valid = false;
            }
    }   

     return valid;
}

Try this regex !

(\+\d{2}|\d{2}-|\d{2}|\d{1})?\d{10}

在此处输入图片说明

You can use the following regex:

(?:\+?91-?\d{10})|(?:0?\d{10})(\,(?:\+?91-?\d{10})|(?:0?\d{10}))*

tested on:

https://regex101.com/r/lQ6nAU/1/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM