Numbered Vanila v1.0.5
Plugin for create an input mask of numbers
el options;
Default options
mask: '+7 (###) ### - ## - ##' // Mask for input value numbered: '#' // Masking definition empty: '_' // Empty masking definition char (or space) placeholder: false // Enable placeholder to mask
NPM
https://www.npmjs.com/package/input.numbered
Initialize
var numberedFromId = '#numbered';
or
var numberedFromClass = '.numbered' mask: '#### - #### - #### - ####' empty: 'X' placeholder: true;
or
var numberedFromTag = 'input';
or
var numberedFromSelector = 'form input.numbered';
or if jQuery included
var $numbered = ;var numberedFromJQuery = $numbered;
setVal
var example3 = '#example3' mask: '## / ## / ####' empty: '-';;;
getVal(raw = false)
var example1 = '#example1';;;
reInit
var example1 = '#example1';;
Validate
Validate method returns 1
- is valid, 0
- is empty, -1
, is invalid. The result can be Integer
or Array
depending on the number of elements. You can listen to your desired events and to validate out at any time.
var $numbered = $('#numbered');
var numbered = new Numbered($numbered);
$numbered.on('change blur input focusin', function () {
var validate = numbered.validate();
$numbered
.toggleClass('error', validate < 0)
.toggleClass('empty', validate === 0)
.toggleClass('valid', validate > 0);
});
Destroy
var numbered = '#numbered';numbered;