jeudi 22 octobre 2020

How can I validate check for a phone number?

let phoneNumber = $('#order-phone').val()

if (phoneNumber.length == 13) {
    parts = phoneNumber.split('-');
    if ((parts[0] == '010') && ((parts[1] >= '0000') && (parts[1] <= '9999')) && ((parts[2] >= '0000') && (parts[2] <= '9999'))) {
        alert('Finished');
    } else {
        alert('Put your number like "010-OOOO-OOOO"');
    }
} else {
    alert('Put your number like "010-OOOO-OOOO"')
}

The situation is like.. The user inputs his phone number as string and then I check the validation for the phone number the user gave to me. 'PhoneNumber' above is string type and I don't know how can I do perfect validate check for the strings that is phone number with 13 characters including numeric characters and hyphen.

Aucun commentaire:

Enregistrer un commentaire