credit card format Regex for validation

 Credit Card validation regex

export const ValidateCreditCardNumber = val => {
    var visaRegEx = /^(?:4[0-9]{12}(?:[0-9]{3})?)$/;
    var masterCardRegEx = /^(?:5[1-5][0-9]{14})$/;
    var americaExpRegEx = /^(?:3[47][0-9]{13})$/;
    var discoverRegEx = /^(?:6(?:011|5[0-9][0-9])[0-9]{12})$/;
    var isValid = false;
    // test numbers
    // 341140185346626.
    // 375727641414391.
    // 373834279838370.
    // 348719775768795.
    // 372653007683820.

    if (visaRegEx.test(val)) {
        isValid = true;
    } else if (masterCardRegEx.test(val)) {
        isValid = true;
    } else if (americaExpRegEx.test(val)) {
        isValid = true;
    } else if (discoverRegEx.test(val) ) {
        isValid = true;
    }
    return isValid
}

Comments

Popular posts from this blog

Image Preview Before upload image into ReactJs

Format mobile number to this format "(845) 963-2545" #mobileFormat