Subversion-Projekte lars-tiefland.ci

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
776 lars 1
# jquery.inputmask 3.x
2
Copyright (c) 2010 - 2015 Robin Herbots Licensed under the MIT license ([http://opensource.org/licenses/mit-license.php](http://opensource.org/licenses/mit-license.php))
3
 
4
[![NPM Version][npm-image]][npm-url] [![Dependency Status][david-image]][david-url] [![devDependency Status][david-dev-image]][david-dev-url]
5
 
6
jquery.inputmask is a jQuery plugin which create an input mask.
7
 
8
An inputmask helps the user with the input by ensuring a predefined format. This can be useful for dates, numerics, phone numbers, ...
9
 
10
Highlights:
11
- easy to use
12
- optional parts anywere in the mask
13
- possibility to define aliases which hide complexity
14
- date / datetime masks
15
- numeric masks
16
- lots of callbacks
17
- non-greedy masks
18
- many features can be enabled/disabled/configured by options
19
- supports readonly/disabled/dir="rtl" attributes
20
- support data-inputmask attribute(s)
21
- alternator-mask support
22
- regex-mask support
23
- dynamic-mask support
24
- preprocessing-mask support
25
- value formatting / validating without input element
26
- AMD/CommonJS support
27
 
28
Demo page see [http://robinherbots.github.io/jquery.inputmask](http://robinherbots.github.io/jquery.inputmask)
29
 
30
[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=ZNR3EB6JTMMSS)
31
 
32
## Usage:
33
Include the js-files which you can find in the dist-folder.
34
 
35
The minimum to include is inputmask.js && jquery.inputmask.js
36
 
37
```html
38
<script src="jquery.js" type="text/javascript"></script>
39
<script src="inputmask.js" type="text/javascript"></script>
40
<script src="jquery.inputmask.js" type="text/javascript"></script>
41
```
42
 
43
If you use a module loader like requireJS, use the js-files in dist/inputmask
44
 
45
```javascript
46
paths: {
47
  ...
48
  "dependencyLib": "../dist/inputmask/dependencyLib",
49
  "inputmask": "../dist/inputmask/inputmask",
50
  ...
51
}
52
```
53
 
54
Define your masks:
55
 
56
```javascript
57
$(document).ready(function(){
58
   $(selector).inputmask("99-9999999");  //static mask
59
   $(selector).inputmask("mask", {"mask": "(999) 999-9999"}); //specifying fn & options
60
   $(selector).inputmask({"mask": "99-9999999"}); //specifying options only
61
   $(selector).inputmask("9-a{1,3}9{1,3}"); //mask with dynamic syntax
62
});
63
```
64
 
65
or via data-inputmask attribute
66
 
67
```html
68
<input data-inputmask="'alias': 'date'" />
69
<input data-inputmask="'mask': '9', 'repeat': 10, 'greedy' : false" />
70
<input data-inputmask="'mask': '99-9999999'" />
71
```
72
 
73
```javascript
74
$(document).ready(function(){
75
    $(":input").inputmask();
76
});
77
```
78
 
79
Any option can also be passed through the use of a data attribute. Use data-inputmask-<**_the name of the option_**>="value"
80
 
81
```html
82
<input id="example1" data-inputmask-clearmaskonlostfocus="false" />
83
<input id="example2" data-inputmask-regex="[a-za-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?" />
84
```
85
 
86
```javascript
87
$(document).ready(function(){
88
   $("#example1").inputmask("99-9999999");
89
   $("#example2").inputmask("Regex");
90
});
91
```
92
 
93
### Allowed HTML-elements
94
- input type="text"
95
- input type="tel"
96
- div contenteditable="true" (and all others supported by contenteditable)
97
- any html-element (mask text content or set maskedvalue with jQuery.val)
98
 
99
### Default masking definitions
100
- 9 : numeric
101
- a : alphabetical
102
  - : alphanumeric
103
 
104
There are more definitions defined within the extensions.<br>You can find info within the js-files or by further exploring the options.
105
 
106
## Masking types
107
### Static masks
108
These are the very basic of masking.  The mask is defined and will not change during the input.
109
 
110
```javascript
111
$(document).ready(function(){
112
   $(selector).inputmask("aa-9999");  //static mask
113
   $(selector).inputmask({mask: "aa-9999"});  //static mask
114
});
115
```
116
 
117
### Optional masks
118
It is possible to define some parts in the mask as optional.  This is done by using [ ].
119
 
120
Example:
121
 
122
```javascript
123
$('#test').inputmask('(99) 9999[9]-9999');
124
```
125
 
126
This mask wil allow input like (99) 99999-9999 or (99) 9999-9999.<br>Input => 12123451234      mask => (12) 12345-1234    (trigger complete)<br>Input => 121234-1234      mask => (12) 1234-1234     (trigger complete)<br>Input => 1212341234       mask => (12) 12341-234_    (trigger incomplete)
127
 
128
#### skipOptionalPartCharacter
129
As an extra there is another configurable character which is used to skip an optional part in the mask.
130
 
131
```javascript
132
skipOptionalPartCharacter: " ",
133
```
134
 
135
Input => 121234 1234      mask => (12) 1234-1234     (trigger complete)
136
 
137
When `clearMaskOnLostFocus: true` is set in the options (default), the mask will clear out the optional part when it is not filled in and this only in case the optional part is at the end of the mask.
138
 
139
For example, given:
140
 
141
```javascript
142
$('#test').inputmask('999[-AAA]');
143
```
144
 
145
While the field has focus and is blank, users will see the full mask `___-___`. When the required part of the mask is filled and the field loses focus, the user will see `123`. When both the required and optional parts of the mask are filled out and the field loses focus, the user will see `123-ABC`.
146
 
147
#### Optional masks with greedy false
148
When defining an optional mask together with the greedy: false option, the inputmask will show the smallest possible mask as input first.
149
 
150
```javascript
151
$(selector).inputmask({ mask: "9[-9999]", greedy: false });
152
```
153
 
154
The initial mask shown will be "**_**" instead of "**_**-____".
155
 
156
### Dynamic masks
157
Dynamic masks can change during the input.  To define a dynamic part use { }.
158
 
159
{n} => n repeats<br>{n,m} => from n to m repeats
160
 
161
Also {+} and {*} is allowed. + start from 1 and * start from 0.
162
 
163
```javascript
164
$(document).ready(function(){
165
   $(selector).inputmask("aa-9{4}");  //static mask with dynamic syntax
166
   $(selector).inputmask("aa-9{1,4}");  //dynamic mask ~ the 9 def can be occur 1 to 4 times
167
 
168
   //email mask
169
   $(selector).inputmask({
170
            mask: "*{1,20}[.*{1,20}][.*{1,20}][.*{1,20}]@*{1,20}[.*{2,6}][.*{1,2}]",
171
            greedy: false,
172
            onBeforePaste: function (pastedValue, opts) {
173
                pastedValue = pastedValue.toLowerCase();
174
                return pastedValue.replace("mailto:", "");
175
            },
176
            definitions: {
177
                '*': {
178
                    validator: "[0-9A-Za-z!#$%&'*+/=?^_`{|}~\-]",
179
                    cardinality: 1,
180
                    casing: "lower"
181
                }
182
            }
183
    });
184
```
185
 
186
### Alternator masks
187
The alternator syntax is like an **OR** statement.  The mask can be one of the 2 choices specified in the alternator.
188
 
189
To define an alternator use the |.<br>ex: "a|9" => a or 9<br>    "(aaa)|(999)" => aaa or 999
190
 
191
Also make sure to read about the keepStatic option.
192
 
193
```javascript
194
$("selector").inputmask("(99.9)|(X)", {
195
                definitions: {
196
                    "X": {
197
                        validator: "[xX]",
198
                        cardinality: 1,
199
                        casing: "upper"
200
                    }
201
                }
202
            });
203
```
204
 
205
or
206
 
207
```javascript
208
$("selector").inputmask({
209
                mask: ["99.9", "X"],
210
                definitions: {
211
                    "X": {
212
                        validator: "[xX]",
213
                        cardinality: 1,
214
                        casing: "upper"
215
                    }
216
                }
217
            });
218
```
219
 
220
### Preprocessing masks
221
You can define the mask as a function which can allow to preprocess the resulting mask.  Example sorting for multiple masks or retrieving mask definitions dynamically through ajax. The preprocessing fn should return a valid mask definition.
222
 
223
```javascript
224
  $(selector).inputmask({ mask: function () { /* do stuff */ return ["[1-]AAA-999", "[1-]999-AAA"]; }});
225
```
226
 
227
## Define custom definitions
228
You can define your own definitions to use in your mask.<br>Start by choosing a masksymbol.
229
 
230
### validator(chrs, maskset, pos, strict, opts)
231
Next define your validator.  The validator can be a regular expression or a function.
232
 
233
The return value of a validator can be true,  false or a command object.
234
 
235
#### Options of the command object
236
- pos : position to insert
237
- c : character to insert
238
- caret : position of the caret
239
- remove : position(s) to remove
240
  - pos or [pos1, pos2]
241
 
242
- insert : position(s) to add :
243
  - { pos : position to insert, c : character to insert }
244
  - [{ pos : position to insert, c : character to insert }, { ...}, ... ]
245
 
246
- refreshFromBuffer :
247
  - true => refresh validPositions from the complete buffer
248
  - { start: , end: } => refresh from start to end
249
 
250
### cardinality
251
Cardinality specifies how many characters are represented and validated for the definition.
252
 
253
### prevalidator(chrs, maskset, pos, strict, opts)
254
The prevalidator option is used to validate the characters before the definition cardinality is reached. (see 'j' example)
255
 
256
### definitionSymbol
257
When you insert or delete characters, they are only shifted when the definition type is the same.  This behavior can be overridden by giving a definitionSymbol. (see example x, y, z, which can be used for ip-address masking, the validation is different, but it is allowed to shift the characters between the definitions)
258
 
259
```javascript
260
Inputmask.extendDefinitions({
261
    'f': {  //masksymbol
262
        "validator": "[0-9\(\)\.\+/ ]",
263
        "cardinality": 1,
264
        'prevalidator': null
265
    },
266
    'g': {
267
        "validator": function (chrs, buffer, pos, strict, opts) {
268
            //do some logic and return true, false, or { "pos": new position, "c": character to place }
269
        }
270
        "cardinality": 1,
271
        'prevalidator': null
272
    },
273
    'j': { //basic year
274
            validator: "(19|20)\\d{2}",
275
            cardinality: 4,
276
            prevalidator: [
277
                        { validator: "[12]", cardinality: 1 },
278
                        { validator: "(19|20)", cardinality: 2 },
279
                        { validator: "(19|20)\\d", cardinality: 3 }
280
            ]
281
     },
282
     'x': {
283
        validator: "[0-2]",
284
        cardinality: 1,
285
        definitionSymbol: "i" //this allows shifting values from other definitions, with the same masksymbol or definitionSymbol
286
     },
287
     'y': {
288
        validator: function (chrs, buffer, pos, strict, opts) {
289
                        var valExp2 = new RegExp("2[0-5]|[01][0-9]");
290
                        return valExp2.test(buffer[pos - 1] + chrs);
291
                    },
292
        cardinality: 1,
293
        definitionSymbol: "i"
294
     },
295
     'z': {
296
        validator: function (chrs, buffer, pos, strict, opts) {
297
                       var valExp3 = new RegExp("25[0-5]|2[0-4][0-9]|[01][0-9][0-9]");
298
                        return valExp3.test(buffer[pos - 2] + buffer[pos - 1] + chrs);
299
        },
300
        cardinality: 1,
301
        definitionSymbol: "i"
302
      }
303
});
304
```
305
 
306
### placeholder
307
Specify a placeholder for a definition.
308
 
309
### set defaults
310
Defaults can be set as below.
311
 
312
```javascript
313
Inputmask.extendDefaults({
314
    'autoUnmask': true
315
});
316
Inputmask.extendDefinitions({
317
  'A': {
318
    validator: "[A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
319
    cardinality: 1,
320
    casing: "upper" //auto uppercasing
321
  },
322
  '+': {
323
    validator: "[0-9A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
324
    cardinality: 1,
325
    casing: "upper"
326
  }
327
});
328
Inputmask.extendAliases({
329
  'Regex': {
330
    mask: "r",
331
    greedy: false,
332
    ...
333
  }
334
});
335
```
336
 
337
But if the property is defined within an alias you need to set it for the alias definition.
338
 
339
```javascript
340
Inputmask.extendAliases({
341
  'numeric' : {
342
    allowPlus: false,
343
    allowMinus: false
344
}});
345
```
346
 
347
However, the preferred way to alter properties for an alias is by creating a new alias which inherits from the default alias definition.
348
 
349
```javascript
350
Inputmask.extendAliases({
351
    'myNum': {
352
            alias: "numeric",
353
            placeholder: '',
354
            allowPlus: false,
355
            allowMinus: false
356
        }
357
});
358
```
359
 
360
Once defined, you can call the alias by:
361
 
362
```javascript
363
 $(selector).inputmask("myNum");
364
```
365
 
366
## Options:
367
### placeholder
368
Change the mask placeholder
369
 
370
```javascript
371
$(document).ready(function(){
372
   $("#date").inputmask("d/m/y",{ "placeholder": "*" });
373
});
374
```
375
 
376
or a multi-char placeholder
377
 
378
```javascript
379
$(document).ready(function(){
380
   $("#date").inputmask("d/m/y",{ "placeholder": "dd/mm/yyyy" });
381
});
382
```
383
 
384
### optionalmarker
385
Definition of the symbols used to indicate an optional part in the mask.
386
 
387
```javascript
388
optionalmarker: { start: "[", end: "]" },
389
```
390
 
391
### quantifiermarker
392
Definition of the symbols used to indicate a quantifier in the mask.
393
 
394
```javascript
395
quantifiermarker: { start: "{", end: "}" },
396
```
397
 
398
### groupmarker
399
Definition of the symbols used to indicate a group in the mask.
400
 
401
```javascript
402
groupmarker: { start: "(", end: ")" },
403
```
404
 
405
### alternatormarker
406
Definition of the symbols used to indicate an alternator part in the mask.
407
 
408
```javascript
409
alternatormarker: "|",
410
```
411
 
412
### escapeChar
413
Definition of the symbols used to escape a part in the mask.
414
 
415
```javascript
416
escapeChar: "\\",
417
```
418
 
419
See **escape special mask chars**
420
 
421
### mask
422
The mask to use.
423
 
424
### oncomplete
425
Execute a function when the mask is completed
426
 
427
```javascript
428
$(document).ready(function(){
429
   $("#date").inputmask("d/m/y",{ "oncomplete": function(){ alert('inputmask complete'); } });
430
});
431
```
432
 
433
### onincomplete
434
Execute a function when the mask is incomplete.  Executes on blur.
435
 
436
```javascript
437
$(document).ready(function(){
438
   $("#date").inputmask("d/m/y",{ "onincomplete": function(){ alert('inputmask incomplete'); } });
439
});
440
```
441
 
442
### oncleared
443
Execute a function when the mask is cleared.
444
 
445
```javascript
446
$(document).ready(function(){
447
   $("#date").inputmask("d/m/y",{ "oncleared": function(){ alert('inputmask cleared'); } });
448
});
449
```
450
 
451
### repeat
452
Mask repeat function. Repeat the mask definition x-times.
453
 
454
```javascript
455
$(document).ready(function(){
456
   $("#number").inputmask({ "mask": "9", "repeat": 10 });  // ~ mask "9999999999"
457
});
458
```
459
 
460
### greedy
461
Toggle to allocate as much possible or the opposite. Non-greedy repeat function.
462
 
463
```javascript
464
$(document).ready(function(){
465
   $("#number").inputmask({ "mask": "9", "repeat": 10, "greedy": false });  // ~ mask "9" or mask "99" or ... mask "9999999999"
466
});
467
```
468
 
469
With the non-greedy option set to false, you can specify * as repeat.  This makes an endless repeat.
470
 
471
### autoUnmask
472
Automatically unmask the value when retrieved.<br>Default: false.
473
 
474
When setting this option to true the plugin also expects the initial value from the server to be unmasked.
475
 
476
### removeMaskOnSubmit
477
Remove the mask before submitting the form.<br>Default: false
478
 
479
### clearMaskOnLostFocus
480
Remove the empty mask on blur or when not empty removes the optional trailing part Default: true
481
 
482
```javascript
483
$(document).ready(function(){
484
    $("#ssn").inputmask("999-99-9999",{placeholder:" ", clearMaskOnLostFocus: true }); //default
485
});
486
```
487
 
488
### insertMode
489
Toggle to insert or overwrite input.<br>Default: true.<br>This option can be altered by pressing the Insert key.
490
 
491
### clearIncomplete
492
Clear the incomplete input on blur
493
 
494
```javascript
495
$(document).ready(function(){
496
   $("#date").inputmask("d/m/y",{ "clearIncomplete": true } });
497
});
498
```
499
 
500
### aliases
501
Definitions of aliases.
502
 
503
With an alias you can define a complex mask definition and call it by using an alias name.  So this is mainly to simplify the use of your masks.  Some aliases found in the extensions are: email, currency, decimal, integer, date, datetime, dd/mm/yyyy, etc.
504
 
505
First you have to create an alias definition.  The alias definition can contain options for the mask, custom definitions, the mask to use etc.
506
 
507
When you pass in an alias, the alias is first resolved and then the other options are applied.  So you can call an alias and pass another mask to be applied over the alias. This also means that you can write aliases which "inherit" from another alias.
508
 
509
Some examples can be found in jquery.inputmask.xxx.extensions.js
510
 
511
use:
512
 
513
```javascript
514
   $("#date").inputmask("date");
515
```
516
 
517
or
518
 
519
```javascript
520
   $("#date").inputmask({ alias: "date"});
521
```
522
 
523
You can also call an alias and extend it with some more options
524
 
525
```javascript
526
   $("#date").inputmask("date", { "clearIncomplete": true });
527
```
528
 
529
or
530
 
531
```javascript
532
   $("#date").inputmask({ alias: "date", "clearIncomplete": true });
533
```
534
 
535
### alias
536
The alias to use.
537
 
538
```javascript
539
   $("#date").inputmask({ alias: "email"});
540
```
541
 
542
### onKeyDown
543
Callback to implement autocomplete on certain keys for example
544
 
545
Function arguments: event, buffer, caretPos, opts<br>Function return:
546
 
547
### onBeforeMask
548
Executes before masking the initial value to allow preprocessing of the initial value.
549
 
550
Function arguments: initialValue, opts<br>Function return: processedValue
551
 
552
```javascript
553
$(selector).inputmask({
554
                alias: 'phonebe',
555
                onBeforeMask: function (value, opts) {
556
                                 var processedValue = value.replace(/^0/g, "");
557
                                if (processedValue.indexOf("32") > 1 ||     processedValue.indexOf("32") == -1) {
558
                                    processedValue = "32" + processedValue;
559
                                }
560
 
561
                                return processedValue;
562
                            }
563
            });
564
```
565
 
566
### onBeforePaste
567
This callback allows for preprocessing the pasted value before actually handling the value for masking.  This can be usefull for stripping away some characters before processing.
568
 
569
Function arguments: pastedValue, opts<br>Function return: processedValue
570
 
571
```javascript
572
$(selector).inputmask({
573
                mask: '9999 9999 9999 9999',
574
                placeholder: ' ',
575
                showMaskOnHover: false,
576
                showMaskOnFocus: false,
577
                onBeforePaste: function (pastedValue, opts) {
578
                    var processedValue = pastedValue;
579
 
580
                    //do something with it
581
 
582
                    return processedValue;
583
                }
584
            });
585
```
586
 
587
You can also disable pasting a value by returning false in the onBeforePaste call.
588
 
589
### onBeforeWrite
590
Executes before writing to the masked element
591
 
592
Use this to do some extra processing of the input. This can be usefull when implementing an alias, ex. decimal alias, autofill the digits when leaving the inputfield.
593
 
594
Function arguments: event, buffer, caretPos, opts<br>Function return: command object (see Define custom definitions)
595
 
596
### onUnMask
597
Executes after unmasking to allow post-processing of the unmaskedvalue.
598
 
599
Function arguments: maskedValue, unmaskedValue<br>Function return: processedValue
600
 
601
```javascript
602
$(document).ready(function(){
603
   $("#number").inputmask("decimal", { onUnMask: function(maskedValue, unmaskedValue) {
604
        //do something with the value
605
        return unmaskedValue;
606
   }});
607
});
608
```
609
 
610
### showMaskOnFocus
611
Shows the mask when the input gets focus. (default = true)
612
 
613
```javascript
614
$(document).ready(function(){
615
    $("#ssn").inputmask("999-99-9999",{ showMaskOnFocus: true }); //default
616
});
617
```
618
 
619
To make sure no mask is visible on focus also set the showMaskOnHover to false.  Otherwise hovering with the mouse will set the mask and will stay on focus.
620
 
621
### showMaskOnHover
622
Shows the mask when hovering the mouse. (default = true)
623
 
624
```javascript
625
$(document).ready(function(){
626
    $("#ssn").inputmask("999-99-9999",{ showMaskOnHover: true }); //default
627
});
628
```
629
 
630
### onKeyValidation
631
Callback function is executed on every keyvalidation with the result as parameter.
632
 
633
```javascript
634
$(document).ready(function(){
635
    $("#ssn").inputmask("999-99-9999",
636
            { onKeyValidation: function (result) {
637
                                console.log(result);
638
                                } });
639
});
640
```
641
 
642
### skipOptionalPartCharacter
643
### showTooltip
644
Show the current mask definition as a tooltip.
645
 
646
```javascript
647
  $(selector).inputmask({ mask: ["999-999-9999 [x99999]", "+099 99 99 9999[9]-9999"], showTooltip: true });
648
```
649
 
650
### numericInput
651
Numeric input direction.  Keeps the caret at the end.
652
 
653
```javascript
654
$(document).ready(function(){
655
    $(selector).inputmask('€ 999.999.999,99', { numericInput: true });    //123456  =>  € ___.__1.234,56
656
});
657
```
658
 
659
### rightAlign
660
Align the input to the right
661
 
662
By setting the rightAlign you can specify to right align an inputmask. This is only applied in combination op the numericInput option or the dir-attribute. Default is true.
663
 
664
```javascript
665
$(document).ready(function(){
666
    $(selector).inputmask('decimal', { rightAlign: false });  //disables the right alignment of the decimal input
667
});
668
```
669
 
670
### undoOnEscape
671
Make escape behave like undo. (ctrl-Z)<br>Pressing escape reverts the value to the value before focus.<br>Default: true
672
 
673
### radixPoint (numerics)
674
Define the radixpoint (decimal separator)<br>Default: ""
675
 
676
### groupSeparator (numerics)
677
Define the groupseparator<br>Default: ""
678
 
679
### radixFocus (numerics)
680
Position the caret to the radixpoint on the initial click into the inputfield.<br>Default: false
681
 
682
### nojumps
683
Do not jump over fixed parts in the mask.<br>Default: false
684
 
685
### nojumpsThreshold
686
Start nojumps as of<br>Default: 0
687
 
688
### keepStatic
689
Default: null (~false) Use in combination with the alternator syntax Try to keep the mask static while typing. Decisions to alter the mask will be postponed if possible.
690
 
691
ex. $(selector).inputmask({ mask: ["+55-99-9999-9999", "+55-99-99999-9999", ], keepStatic: true });
692
 
693
typing 1212345123 => should result in +55-12-1234-5123 type extra 4 => switch to +55-12-12345-1234
694
 
695
When passing multiple masks (an array of masks) keepStatic is automatically set to true unless explicitly set through the options.
696
 
697
### positionCaretOnTab
698
When enabled the caret position is set after the latest valid position on TAB
699
Default: false
700
 
701
### tabThrough
702
Allows for tabbing through the different parts of the masked field.
703
Default: false
704
 
705
### definitions
706
### ignorables
707
### isComplete
708
With this call-in (hook) you can override the default implementation of the isComplete function.<br>Args => buffer, opts Return => true|false
709
 
710
```javascript
711
$(selector).inputmask("Regex", {
712
    regex: "[0-9]*",
713
    isComplete: function(buffer, opts) {
714
        return new RegExp(opts.regex).test(buffer.join(''));
715
    }
716
});
717
```
718
 
719
### canClearPosition
720
Hook to alter the clear behavior in the stripValidPositions<br>Args => maskset, position, lastValidPosition, opts<br>Return => true|false
721
 
722
### postValidation
723
Hook to postValidate the result from isValid.  Usefull for validating the entry as a whole.  Args => buffer, opts<br>Return => true|false
724
 
725
## Functions
726
### mask
727
Create a mask for the input.
728
 
729
```javascript
730
$(document).ready(function(){
731
   $(selector).inputmask('mask', { mask: "99-999-99"});
732
});
733
```
734
 
735
### unmaskedvalue
736
Get the unmaskedvalue
737
 
738
```javascript
739
$(document).ready(function(){
740
   $(selector).inputmask('unmaskedvalue');
741
});
742
```
743
 
744
### remove
745
Remove the inputmask.
746
 
747
```javascript
748
$(document).ready(function(){
749
    $(selector).inputmask('remove');
750
});
751
```
752
 
753
### getemptymask
754
return the default (empty) mask value
755
 
756
```javascript
757
$(document).ready(function(){
758
   $("#test").inputmask("999-AAA");
759
   var initialValue = $("#test").inputmask("getemptymask");  // initialValue  => "___-___"
760
});
761
```
762
 
763
### hasMaskedValue
764
Check whether the returned value is masked or not; currently only works reliably when using jquery.val fn to retrieve the value
765
 
766
```javascript
767
$(document).ready(function(){
768
    function validateMaskedValue(val){}
769
    function validateValue(val){}
770
 
771
    var val = $("#test").val();
772
    if($("#test").inputmask("hasMaskedValue"))
773
      validateMaskedValue(val);
774
   else validateValue(val);
775
});
776
```
777
 
778
### isComplete
779
Verify whether the current value is complete or not.
780
 
781
```javascript
782
$(document).ready(function(){
783
    if($(selector).inputmask("isComplete")){
784
        //do something
785
    }
786
});
787
```
788
 
789
### getmetadata
790
The metadata of the actual mask provided in the mask definitions can be obtained by calling getmetadata.  If only a mask is provided the mask definition will be returned by the getmetadata.
791
 
792
```javascript
793
$(selector).inputmask("getmetadata");
794
```
795
 
796
### setvalue
797
The setvalue functionality is to set a value to the inputmask like you would do with jQuery.val, BUT it will trigger the internal event used by the inputmask always, whatever the case. This is particular usefull when cloning an inputmask with jQuery.clone.  Cloning an inputmask is not a fully functional clone.  On the first event (mouseenter, focus, ...) the inputmask can detect if it where cloned an can reactivate the masking.  However when setting the value with jQuery.val there is none of the events triggered.  The setvalue functionality does this for you.
798
 
799
### option
800
Get or set an option on an existing inputmask.
801
 
802
```javascript
803
$("#CellPhone").inputmask("option", {
804
  onBeforePaste: function (pastedValue, opts) {
805
      return phoneNumOnPaste(pastedValue, opts);
806
  }
807
})
808
$("#CellPhone").inputmask("option", "onBeforePaste")
809
```
810
 
811
## General
812
### set a value and apply mask
813
this can be done with the traditional jquery.val function (all browsers) or JavaScript value property for browsers which implement lookupGetter or getOwnPropertyDescriptor
814
 
815
```javascript
816
$(document).ready(function(){
817
   $("#number").val(12345);
818
 
819
   var number = document.getElementById("number");
820
   number.value = 12345;
821
});
822
```
823
 
824
with the autoUnmaskoption you can change the return of $.fn.val (or value property) to unmaskedvalue or the maskedvalue
825
 
826
```javascript
827
$(document).ready(function(){
828
       $('#<%= tbDate.ClientID%>').inputmask({ "mask": "d/m/y", 'autoUnmask' : true});    //  value: 23/03/1973
829
    alert($('#<%= tbDate.ClientID%>').val());    // shows 23031973     (autoUnmask: true)
830
 
831
    var tbDate = document.getElementById("<%= tbDate.ClientID%>");
832
    alert(tbDate.value);    // shows 23031973     (autoUnmask: true)
833
});
834
```
835
 
836
### escape special mask chars
837
 
838
```javascript
839
$(document).ready(function(){
840
    $("#months").inputmask("m \\months");
841
});
842
```
843
 
844
### auto upper/lower- casing inputmask
845
You can define within a definition to automatically lowercase or uppercase the entry in an input by giving the casing.<br>Casing can be null, "upper" or "lower"
846
 
847
```javascript
848
   Inputmask.extendDefinitions({
849
        'A': {
850
            validator: "[A-Za-z]",
851
            cardinality: 1,
852
            casing: "upper" //auto uppercasing
853
        },
854
        '+': {
855
            validator: "[A-Za-z\u0410-\u044F\u0401\u04510-9]",
856
            cardinality: 1,
857
            casing: "upper"
858
        }
859
    });
860
```
861
 
862
Include jquery.inputmask.extensions.js for using the A and # definitions.
863
 
864
```javascript
865
$(document).ready(function(){
866
   $("#test").inputmask("999-AAA");    //   => 123abc ===> 123-ABC
867
});
868
```
869
 
870
## Supported markup options
871
### RTL attribute
872
 
873
```html
874
<input id="test" dir="rtl" />
875
```
876
 
877
### readonly attribute
878
 
879
```html
880
<input id="test" readonly="readonly" />
881
```
882
 
883
### disabled attribute
884
 
885
```html
886
<input id="test" disabled="disabled" />
887
```
888
 
889
### maxlength attribute
890
 
891
```html
892
<input id="test" maxlength="4" />
893
```
894
 
895
### data-inputmask attribute
896
You can also apply an inputmask by using the data-inputmask attribute.  In the attribute you specify the options wanted for the inputmask. This gets parsed with $.parseJSON (for the moment), so be sure to use a well-formed json-string without the {}.
897
 
898
```html
899
<input data-inputmask="'alias': 'date'" />
900
<input data-inputmask="'mask': '9', 'repeat': 10, 'greedy' : false" />
901
```
902
 
903
```javascript
904
$(document).ready(function(){
905
    $(":input").inputmask();
906
});
907
```
908
 
909
### data-inputmask-<option\> attribute
910
All options can also be passed through data-attributes.
911
 
912
```html
913
<input data-inputmask-mask="9" data-inputmask-repeat="10" data-inputmask-greedy="false" />
914
```
915
 
916
```javascript
917
$(document).ready(function(){
918
    $(":input").inputmask();
919
});
920
```
921
 
922
## Value formatting
923
Instead of masking an input element it is also possible to use the inputmask for formatting given values. Think of formatting values to show in jqGrid or on other elements then inputs.
924
 
925
```javascript
926
var formattedDate =Inputmask.format("2331973", { alias: "dd/mm/yyyy"});
927
```
928
 
929
## Value unmasking
930
Unmask a given value against the mask.
931
 
932
```javascript
933
var unformattedDate =Inputmask.unmask("23/03/1973", { alias: "dd/mm/yyyy"}); //23031973
934
```
935
 
936
## Value validating
937
Validate a given value against the mask.
938
 
939
```javascript
940
var isValid =Inputmask.isValid("23/03/1973", { alias: "dd/mm/yyyy"});
941
```
942
 
943
## jQuery.clone
944
When cloning a inputmask, the inputmask reactivates on the first event (mouseenter, focus, ...) that happens to the input. If you want to set a value on the cloned inputmask and you want to directly reactivate the masking you have to use $(input).inputmask("setvalue", value)
945
 
946
# jquery.inputmask extensions
947
## [date & datetime extensions](README_date.md)
948
## [numeric extensions](README_numeric.md)
949
## [regex extensions](README_regex.md)
950
## [phone extensions](README_phone.md)
951
## [other extensions](README_other.md)
952
 
953
[npm-url]: https://npmjs.org/package/jquery.inputmask
954
[npm-image]: https://img.shields.io/npm/v/jquery.inputmask.svg
955
[david-url]: https://david-dm.org/RobinHerbots/jquery.inputmask#info=dependencies
956
[david-image]: https://img.shields.io/david/RobinHerbots/jquery.inputmask.svg
957
[david-dev-url]: https://david-dm.org/RobinHerbots/jquery.inputmask#info=devDependencies
958
[david-dev-image]: https://img.shields.io/david/dev/RobinHerbots/jquery.inputmask.svg