igorescobar / jQuery-Mask-Plugin

A jQuery Plugin to make masks on form fields and HTML elements.
http://igorescobar.github.io/jQuery-Mask-Plugin/
Other
4.77k stars 1.42k forks source link

How to use or not the percentage symbol (%)? #719

Open tiagocaus opened 5 years ago

tiagocaus commented 5 years ago

How to allow inclusion of the % symbol in the field?

The same field is used as a fixed value and or a percentage value.

In the same field, it can be:

1,45 (one dollar and forty-five cents) or 1,45% (one point forty-five percent)

Thank you.

tiagocaus commented 5 years ago
$(document).ready(function() {
    $(".moeda").mask("#.##0,00%", {
        reverse: true,
        translation: {
            "%": {
                pattern: /\%/,
                optional: true
            }
        }
    });
});