Velocity, Scripting: padding scanned data with zeros

Version 2

    this script goes over how to pad your scanned to a given number..

     

    Example:

    You need to have all scanned be a length of 12.

    this script will shorten from the end all scripts longer than 12 or add 0's to the beginning of the scanned to make it a length of 12..

     

    Scanned: 1234567891234

    Returned: 123456789123

     

    Scanned: 123456

    Returned: 000000123456

     

    Script:

    function onScan(event)

    {

        var len = event.data.length;  

     

        if (len < nLength)

        {

            // pad data with zeros upto length of 11 characters

            for (i=0; i < (nLength- len); i++)

            {

                            event.data  = "0" + event.data;

            }

        }

        else if (len > nLength)

        {

            event.data = event.data.substr(0, nLength) ;

         }

    }

    WLEvent.on("Scan", onScan);

     

    Parameter:

    Name: nLength

    Display Name: nLength

    Description: limits barcodes to the length set by nLength

    default value: 0

    RegEx: ^[0-9]+$

     

    In the above screen shot the value of 12 can be edited to the value you need.