Biblioteca de máscara de entrada minimalista-máscaras de entrada

Tiempo de ejecución: 30 minutos. Empezar

Autor: austinwulf
Views Total: 2,879
Sitio oficial: Ir a la web
Actualizado: June 28, 2016
Licencia: MIT

Vista prévia

Biblioteca de máscara de entrada minimalista-máscaras de entrada

Descripción

Máscaras de entrada es una biblioteca de JavaScript nativa vainilla para enmascarar campos de entrada con formatos de máscara personalizados, marcadores de posición y devoluciones de llamada.

Funcionamiento

Simplemente incluya el archivo JavaScript principal en la página web y ya está.

<script src="index.js"></script>

El JavaScript para enmascarar un campo de entrada específico.

inputMask(document.getElementById('test_field'), {


/**

 * mask

 *

 * Defines the format of the mask.

 * Built-in identifiers:

 *
 #: [0-9]

 *
 a: [A-Za-z]

 */


mask: '###-##-####',


/**

 * placeholder

 *

 * A value to be displayed when the

 * field is in focus. Defaults to the

 * mask string.

 */


placeholder: '___-__-____',


/**

 * onMatch

 *

 * A function to be run on blur if the

 * input value matches the mask.

 *

 * @param {String} The passing string

 */


onMatch: function(value) {


console.log('Value ' + value + ' matches the input mask.');

},


/**

 * onFail

 *

 * A function to be run on blur if the

 * input value does not match the mask.

 */


onFail: function() {


console.log('No match was found for that value.');

},


/**

 * clearOnFail

 *

 * When true, the input field will have its

 * value cleared on blur if the value does

 * not match the mask. Defaults to true.

 */


clearOnFail: false

});

Te puede interesar: