An open API service indexing awesome lists of open source software.

https://github.com/andreypostal/jsgroupmask

Group of masks for input, with different number patterns.
https://github.com/andreypostal/jsgroupmask

html-element javascript js mask

Last synced: 8 months ago
JSON representation

Group of masks for input, with different number patterns.

Awesome Lists containing this project

README

          

# JSGroupMask

Group of masks for input, with different number patterns.

Crie máscaras dinâmicas para os seus inputs de texto, como CPF e CNPJ, telefones fixos e celulares, etc.

## How to use

- Import the file **mask.js**

Importe o arquivo **mask.js**

- Create the input that will receive the mask

Crie o input que receberá a máscara

```html

```

- Instantiate the mask to it, having as parameters the ID and an array with the masks

Instancie a máscara a ele, passando como parâmetro seu ID e um array contendo as máscaras.

```javascript
let mask_cpf_cnpj = new Mask("cpf-cnpj", [
"__.___.___/____-__",
"___.___.___-__",
]);

let mask_phone = new Mask("phone", [
"+__ (__) ____-____",
"+__ (__) _____-____",
"+___ (__) _____-____",
]);
```

The char **\_** will be the space filled by numbers. Other characters (except for numbers) will be considered separators.

Os caracteres **\_** serão os espaços preenchidos por números. Demais caracteres (exceto números) serão considerados separadores.

- Call the method **update** whenever you want to apply the mask to the current value of the input

Chame o método **update** sempre que quiser aplicar a máscara no valor atual do input.

```javascript
mask_cpf_cnpj.update();
mask_phone.update();
```

As in the example, applying the method to every key pressed, we can use the following code:

Como no exemplo, aplicando o método para todo char inserido, podemos usar o trecho de código:

```javascript
$("#cpf-cnpj").keyup(function () {
mask_cpf_cnpj.update();
});

$("#phone").keyup(function () {
mask_phone.update();
});
```

_Version developted really quickly, it is really simples, has some bugs, but does the job_

_Versão desenvolvida rapidamente, é muito simples, tem alguns bugs, mas faz o que precisa_