From 385e3a093c3a0a9cc7a450ca698638f450f5039f Mon Sep 17 00:00:00 2001 From: Kryazhev Alexey Date: Wed, 27 Sep 2017 15:27:13 +0300 Subject: [PATCH 1/2] fix to work with global regexp --- src/masked/regexp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/masked/regexp.js b/src/masked/regexp.js index b107e2f9..17e22f3e 100644 --- a/src/masked/regexp.js +++ b/src/masked/regexp.js @@ -4,7 +4,7 @@ import Masked from './base'; export default class MaskedRegExp extends Masked { constructor (opts={}) { - opts.validate = (value) => opts.mask.test(value); + opts.validate = (value) => value.search(opts.mask) >= 0; super(opts); } } From 6edcf2ec25f3afa478f5f456a024dce1edfcbe0c Mon Sep 17 00:00:00 2001 From: Kryazhev Alexey Date: Fri, 29 Sep 2017 11:17:59 +0300 Subject: [PATCH 2/2] fix guide typos --- guide.html | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/guide.html b/guide.html index 0a6e635c..5cc03efb 100644 --- a/guide.html +++ b/guide.html @@ -60,7 +60,7 @@

Getting St

Basic use case:

var mask = new IMask(element, maskOptions);
-

Get/set value and unmasked value

+

Get/set value and unmasked value:

mask.value = "+7(999)999-99-99";
 console.log(mask.value);  // logs "+7(999)999-99-99"
 console.log(mask.unmaskedValue);  // logs "79999999999"
@@ -69,20 +69,20 @@ 

Getting St console.log(mask.value); // logs "+7(000)000-00-00" console.log(mask.unmaskedValue); // logs "70000000000"

-

Get/set mask

+

Get/set mask:

mask.mask = "000-000"; // auto-updates UI
-

Update options

+

Update options:

mask.updateOptions({
   mask: Number,
   min: 0,
   max: 100
 });  // also updates UI
-

Clean and destroy

+

Clean and destroy:

mask.destroy();
-

Listen to events

+

Listen to events:

// 'accept' event fired on input when mask value has changed
 function log () {console.log(mask.value)};
 mask.on("accept", log);
@@ -91,13 +91,13 @@ 

Getting St // This makes sense only for Pattern-based masks mask.on("complete", function () {console.log(mask.value)});

-

Stop listening to events

+

Stop listening to events:

mask.off("accept", log);
 
 // omit handler argument to unlisten all
 mask.off("complete");
-

Get masked model

+

Get masked model:

var masked = mask.masked;
 masked.reset(); // UI will NOT be updated
@@ -157,13 +157,13 @@

Common

var digitsMask = new IMask(element, {
   mask: /^\d+$/
 });
-

Get/set mask (only same type allowed!)

+

Get/set mask (only same type allowed!):

masked.mask = /^\w+$/;  // ok
 masked.mask = "0000";  // ERROR! changing mask type on existing mask is not allowed!
-

Get/set value and unmasked value

+

Get/set value and unmasked value:

masked.value = 'hello world!';
 console.log(masked.unmaskedValue);
-

Use prepare (value, masked) option for preprocessing input and commit (value, masked) option for postprocessing after UI was deactivated:

+

Use prepare (value, masked) option for preprocessing input and commit (value, masked) option for postprocessing after UI is deactivated:

@@ -187,7 +187,7 @@

Common

masked._value = value.toLowerCase(); // Don't do it } }); -

Usually you don't need to manually create instances of that type, because it will be done by IMask internally. But you can subclass from it to add some specific behavior.

+

Usually you don't need to create instances of that type manually, because it will be done by IMask internally. But you can subclass from it to add some specific behavior.

Additionaly to mask option you can pass custom validator as validate (value, masked) option for some complex checks on any mask types excluding Function and RegExp, because they are already validators themselves. But don't change masked instance inside callbacks.

Also make sure that your mask or validator works with any of intermediate states, not just final value. For example you want to restrict input to "123" and do:

@@ -379,7 +379,7 @@

Pattern

}, // use range to restrict input to numbers in range - // mask size is the length in chars of max bound or could be provided as second parameter + // mask size is the length in chars of max bound or can be provided as second parameter // to input smaller values pad zeros at beginning MM: new IMask.MaskedPattern.Group.Range([1, 12], /* optional size */), @@ -461,7 +461,7 @@

Number

// other options are optional with defaults scale: 2, // digits after point, 0 for integers signed: false, // disallow negative - thousandsSeparator: '', // could be any single char + thousandsSeparator: '', // any single char postFormat: { padFractionalZeros: false, // if true, then pads zeros at end to the length of scale normalizeZeros: true // appends or removes zeros at ends @@ -469,7 +469,7 @@

Number

radix: ',', // fractional delimiter mapToRadix: ['.'] // symbols to process as radix - // number interval options additionally could be set (e.g.) + // additional number interval options (e.g.) min: -10000, max: 10000 }); @@ -521,7 +521,7 @@

Date

min: new Date(2000, 0, 1), // defaults to 1900-01-01 max: new Date(2020, 0, 1), // defaults to 9999-01-01 - // also Pattern options could be set + // also Pattern options can be set placeholder: {lazy: false} });

Easy integration with Moment.js:

@@ -696,7 +696,7 @@

Date

}, // use range to restrict input to numbers in range - // mask size is the length in chars of max bound or could be provided as second parameter + // mask size is the length in chars of max bound or can be provided as second parameter // to input smaller values pad zeros at beginning MM: new IMask.MaskedPattern.Group.Range([1, 12] /*, optional size */),