angular-input-masks icon indicating copy to clipboard operation
angular-input-masks copied to clipboard

mask for RG (registro geral)

Open aj07mm opened this issue 8 years ago • 8 comments

make a mask for RG like "23.344.023-1"

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/33359286-mask-for-rg-registro-geral?utm_campaign=plugin&utm_content=tracker%2F1022469&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F1022469&utm_medium=issues&utm_source=github).

aj07mm avatar Apr 26 '16 19:04 aj07mm

+1, and I can contribute if @assisrafael likes this feature

darlanmendonca avatar Apr 26 '16 20:04 darlanmendonca

A pull request is certainly welcome! =)

assisrafael avatar Apr 27 '16 14:04 assisrafael

this would turn this module into a complete set of masks for pt-br webapps. I'll take a look into this this weekend :)

rcrodrigues avatar May 05 '16 19:05 rcrodrigues

@darlanmendonca @rcrodrigues have you started working on this? If not, I'll work on it :)

detinho avatar Jun 12 '16 01:06 detinho

I have interest in this feature too, also for RNE. @detinho: do you have started?

gnomex avatar Jul 07 '16 13:07 gnomex

I am create the simple directive, based http://pt.stackoverflow.com/questions/22431/express%C3%A3o-regular-para-rg

(function () {

angular
    .module("myApp")
    .directive('rg', RG);

function RG() {
    var directive = {
        require: 'ngModel',
        link: function (scope, element, attr, ngModelCtrl) {
            function parserRG(rg) {
                if (rg) {
                    rg = rg.replace(/\D/g, ""); 
                    rg = rg.replace(/(\d{1,2})(\d{3})(\d{3})(\d{1})$/, "$1.$2.$3-$4");
                    ngModelCtrl.$setViewValue(rg);
                    ngModelCtrl.$render();
                    return rg;
                }
                return undefined;
            }
            ngModelCtrl.$parsers.push(parserRG);
        }
    };
    return directive;}})();

gabrieldevelops avatar Jul 18 '16 15:07 gabrieldevelops

Good answer @gabrieldevelops but this code have one little problem. Some RG has 'X' char as verify code.

I fix it change these lines:

rg = rg.replace(/\D/g, ""); 
rg = rg.replace(/(\d{1,2})(\d{3})(\d{3})(\d{1})$/, "$1.$2.$3-$4");

to:

rg = rg.replace(/(?!X)\D/g, "");
rg = rg.replace(/(\d{1,2})(\d{3})(\d{3})([\dX])$/, "$1.$2.$3-$4");

Now the 'X' char can be input in field. The problem now is the 'X' char can be input anywhere on field.

Someone has ideia how fix it now?

(sorry for my Tupiniquim English)

Thanks!

rafaeldev avatar Jan 07 '17 11:01 rafaeldev

Any news?

LuanGarrido avatar Nov 29 '17 01:11 LuanGarrido