Velocity, Scripting: padding scanned data with zeros

Version 2

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



    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



    function onScan(event)


        var len =;  


        if (len < nLength)


            // pad data with zeros upto length of 11 characters

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


                    = "0" +;



        else if (len > nLength)


   =, nLength) ;



    WLEvent.on("Scan", onScan);



    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.