123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              








//############ VALIDATORS ####################################

function advanced_string_validation(str) {
    //cheks for 3 same later on the row

    for (i = 0; i < str.length; i++) {
        if (str[i] == str[i + 1]) {
            if (str[i] == str[i + 2]) {
                return false;
            }
        }
    }
    return true;
}

function sin_luhn(str, err_text) {
    //Canadian SIN validator
    var str = str.match(/\d/g).join("");

    var luhnArr = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9];
    var counter = 0;
    var incNum;
    var odd = false;
    var temp = String(str).replace(/[^\d]/g, "");
    if (temp.length == 0) return false;
    for (var i = temp.length - 1; i >= 0; --i) {
        incNum = parseInt(temp.charAt(i), 10);
        counter += (odd = !odd) ? incNum : luhnArr[incNum];
    }
    return counter % 10 == 0;
}

function cc_luhn(str, err_text) {
    //CC validator
    var str = str.match(/\d/g).join("");

    var valid =
        str.split("").reduceRight(function(prev, curr, idx) {
            prev = parseInt(prev, 10);
            if ((idx + 1) % 2 !== 0) {
                curr = (curr * 2).toString().split("").reduce(function(p, c) {
                    return parseInt(p, 10) + parseInt(c, 10);
                });
            }
            return prev + parseInt(curr, 10);
        }) %
        10 ===
        0;
    if (!valid) {
        err_text.push("Card number is not valid");
    }

    return valid;
}

function dob_luhn(str, err_text) {
    //DOB input text validation
    //must be separated by /

    var valid = true;
    var d = new Date();
    var yearToday = d.getFullYear();

    var the_day = str.split("/")[0];
    var the_month = str.split("/")[1];
    var the_year = str.split("/")[2];

    if (the_day > 31) {
        valid = false;
    }
    if (the_month > 12) {
        valid = false;
    }
    if (the_year > yearToday) {
        valid = false;
    }
    if (the_year < yearToday - 100) {
        valid = false;
    }
    if (!valid) {
        err_text.push("Date of birth is not valid");
    }
    return valid;
}

function exp_luhn(str, err_text) {
    //EXP input text validation
    //must be separated by /

    var valid = true;
    var d = new Date();
    var yearToday = d.getFullYear();

    var the_month = str.split("/")[0];
    var the_year = "20" + str.split("/")[1];

    if (the_month > 12) {
        valid = false;
    }
    if (the_year < yearToday) {
        valid = false;
    }
    if (the_year > yearToday + 10) {
        valid = false;
    }
    if (!valid) {
        err_text.push("Card expiration date is not valid");
    }
    return valid;
}








var qasame__ = function(err_text) {
    var res = true;
    if (!valid_a(err_text)) {
        res = false;
    }

    if (!valid_q(err_text)) {
        res = false;
    }
    return res;
}





// validate answer for same value

function valid_a(err_text) {
    var arr = $(".answers")
        .map(function() {
            return $(this).val();
        })
        .get();
    if ($.unique(arr).length != $(".answers").length) {
        err_text.push(
            "You can not choose two identical answers. (Error # AE1007-3)"
        );
        return false;
    }
    return true;
}

// validate question for same value

function valid_q(err_text) {
    var arr = $(".questions_")
        .map(function() {
            return $(this).val();
        })
        .get();
    if ($.unique(arr).length != $(".questions_").length) {
        err_text.push(
            "You can not choose two identical questions. (Error # AE1007-3)"
        );
        return false;
    }
    return true;
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console