How to insert this JS validation for NRIC field

Home Forums Quform WordPress How to insert this JS validation for NRIC field

This topic is: not resolved

This topic contains 1 reply, has 2 voices, and was last updated by  Ally 1 week ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #23336

    mynotion
    Participant

    I wanna put in this JS for validate correct Singapore NRIC field. How and where can I insert this code on Quform 1.8x?

    https://gist.github.com/eddiemoore/7131781

    //Based on http://www.samliew.com/icval/
    function validateNRIC(str) {
    if (str.length != 9)
    return false;

    str = str.toUpperCase();

    var i,
    icArray = [];
    for(i = 0; i < 9; i++) {
    icArray[i] = str.charAt(i);
    }

    icArray[1] = parseInt(icArray[1], 10) * 2;
    icArray[2] = parseInt(icArray[2], 10) * 7;
    icArray[3] = parseInt(icArray[3], 10) * 6;
    icArray[4] = parseInt(icArray[4], 10) * 5;
    icArray[5] = parseInt(icArray[5], 10) * 4;
    icArray[6] = parseInt(icArray[6], 10) * 3;
    icArray[7] = parseInt(icArray[7], 10) * 2;

    var weight = 0;
    for(i = 1; i < 8; i++) {
    weight += icArray[i];
    }

    var offset = (icArray[0] == "T" || icArray[0] == "G") ? 4:0;
    var temp = (offset + weight) % 11;

    var st = ["J","Z","I","H","G","F","E","D","C","B","A"];
    var fg = ["X","W","U","T","R","Q","P","N","M","L","K"];

    var theAlpha;
    if (icArray[0] == "S" || icArray[0] == "T") { theAlpha = st[temp]; }
    else if (icArray[0] == "F" || icArray[0] == "G") { theAlpha = fg[temp]; }

    return (icArray[8] === theAlpha);
    }

    #23413

    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.