JSFiddle - React, Tailwind, and code Playground

by whitewolf

JavaScript

self.onlyAllowNum = function (event, isCurrency, value) {
            var which = event.which;
            if (!(smallKeyBoard(which) || numberKeyBpoard(which) || functionKeyBoard(which) || (isCurrency && currencyKeyBoard(which, value)))) {
                event.stopPropagation();
                event.preventDefault();
            }
        };

        self.selectInput = function (event) {
            $timeout(function () {
                event.target.select();
            });
        }


        self.price2number = function (val) {
            return (val || "").trim().replace(/\$|,/g, "");
        };


        var smallKeyBoard = function (which) {
            return (which >= 96 && which <= 105);
        };

        var numberKeyBpoard = function (which) {
            return (which >= 48 && which <= 57);
        };

        var functionKeyBoard = function (which) {
            return (which <= 40);
        };

        var currencyKeyBoard = function (which, value) {
            return  [188].indexOf(which) != -1 || ((( which === 190 || which === 110) && value.toString().indexOf('.') === -1));
        };