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.
- Host: GitHub
- URL: https://github.com/andreypostal/jsgroupmask
- Owner: andreypostal
- Created: 2020-09-21T17:58:30.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-09-22T01:11:40.000Z (over 5 years ago)
- Last Synced: 2025-06-01T15:24:05.118Z (9 months ago)
- Topics: html-element, javascript, js, mask
- Language: JavaScript
- Homepage:
- Size: 10.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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_