Skip to content

fieldmask/javascript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation



FieldMask

A simple masking library for javascript input

License-MIT  

Installation

CDN

<script src="https://fieldmask.github.io/cdnjs/0.1.0/fieldmask.js"></script>

How to use

<input type="text" fieldmask="maskname"> <!-- 'maskname' -->

<!-- cdn -->
<script src="https://fieldmask.github.io/cdnjs/0.1.0/fieldmask.js"></script>
<script>
    fieldmask()
</script>

Predefined Masks

Mask Name Mask Format
cpf 000.000.000-00
cnpj 00.000.000/0000-00
tel 0000-0000
ddd+tel (00) 0000-0000
cel 00000-0000
ddd+cel (00) 00000-0000
cep 00000-000
date 00/00/0000
time 00:00:00
dateTime 00/00/0000 00:00:00
currency ["000.000.000,00", { reverse: true}]
centimeter ["000", { reverse: true, suffix: "cm" }]
meter ["0000", { reverse: true, suffix: "m" }]
ip 000.000.000.000
letter [a-z] [A-Z]
number [0-9]

⭐ How to create custom maskt format

Indicator for define mask: 0

- Example with string only

<input type="text" fieldmask="date">
fieldmask({
    'date': '00-00-0000'
})

- Mask options type

fieldmask({
    'customMaskName': string | [maskFormat, options?: {
        reverse: boolean, // Reverse the typing start side 
        prefix: string,   // prefix+mask
        suffix: string,   // mask+suffix
    }]
})

- Example with options

<input type="text" fieldmask="real">
fieldmask({
    'real': ['00,00', {prefix: 'R$', reverse: true}]
})


©fieldmask | License MIT