RobinHerbots / Inputmask

Input Mask plugin
https://robinherbots.github.io/Inputmask/
MIT License
6.39k stars 2.17k forks source link

Is it possible to have mask with digits in range {min:1,max:100} #1173

Open surjit opened 8 years ago

surjit commented 8 years ago

is it possible to mask only digits in certain range {min:1,max:100}

RobinHerbots commented 8 years ago

@surjit ,

This is not possible out of the box. You can tweak the postValidation in the numeric alias to allow it. I can include it in a future release.

surjit commented 8 years ago

please give me example, how to use it or docs

RobinHerbots commented 8 years ago
    Inputmask.extendAliases({
            "mynumeric": {
                                 alias: "numeric",
                                 postValidation: function(buffer, currentResult, opts) {
                    var isValid = true,
                        maskedValue = opts.numericInput ? buffer.slice().reverse().join("") : buffer.join(""),
                        processValue = maskedValue.replace(opts.prefix, "");
                    processValue = processValue.replace(opts.suffix, "");
                    processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
                    if (opts.radixPoint === ",") processValue = processValue.replace(Inputmask.escapeRegex(opts.radixPoint), ".");
                    //handle negation symbol
                    processValue = processValue.replace(new RegExp("^" + Inputmask.escapeRegex(opts.negationSymbol.front)), "-");
                    processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), "");
                    processValue = processValue === opts.negationSymbol.front ? processValue + "0" : processValue;

                    if (isFinite(processValue)) {

// ADD CODE TO CHECK THE MIN MAX FOR DIGITS
                    }

                    return isValid;
                }
});