Advertisement
hercioneto

examples.js

Apr 16th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(function() {
  2.   $('.date').mask('00/00/0000');
  3.   $('.time').mask('00:00:00');
  4.   $('.date_time').mask('00/00/0000 00:00:00');
  5.   $('.cep').mask('00000-000');
  6.   $('.phone').mask('0000-0000');
  7.   $('.phone_with_ddd').mask('(00) 0000-0000');
  8.   $('.phone_us').mask('(000) 000-0000');
  9.   $('.mixed').mask('AAA 000-S0S');
  10.   $('.ip_address').mask('099.099.099.099');
  11.  
  12.  
  13.   $('.selectonfocus').mask("00/00/0000", {selectOnFocus: true});
  14.  
  15.   $('.cep_with_callback').mask('00000-000', {onComplete: function(cep) {
  16.       console.log('Mask is done!:', cep);
  17.     },
  18.      onKeyPress: function(cep, event, currentField, options){
  19.       console.log('An key was pressed!:', cep, ' event: ', event, 'currentField: ', currentField.attr('class'), ' options: ', options);
  20.     },
  21.     onInvalid: function(val, e, field, invalid, options){
  22.       var error = invalid[0];
  23.       console.log ("Digit: ", error.v, " is invalid for the position: ", error.p, ". We expect something like: ", error.e);
  24.     }
  25.   });
  26.  
  27.   $('.crazy_cep').mask('00000-000', {onKeyPress: function(cep, e, field, options){
  28.     var masks = ['00000-000', '0-00-00-00'];
  29.       mask = (cep.length>7) ? masks[1] : masks[0];
  30.     $('.crazy_cep').mask(mask, options);
  31.   }});
  32.  
  33.   $('.cnpj').mask('00.000.000/0000-00', {reverse: true});
  34.   $('.cpf').mask('000.000.000-00', {reverse: true});
  35.   $('.money').mask('#.##0,00', {reverse: true});
  36.  
  37.   var SPMaskBehavior = function (val) {
  38.     return val.replace(/\D/g, '').length === 11 ? '(00) 00000-0000' : '(00) 0000-00009';
  39.   },
  40.   spOptions = {
  41.     onKeyPress: function(val, e, field, options) {
  42.         field.mask(SPMaskBehavior.apply({}, arguments), options);
  43.       }
  44.   };
  45.  
  46.   $('.sp_celphones').mask(SPMaskBehavior, spOptions);
  47.  
  48.   $(".bt-mask-it").click(function(){
  49.     $(".mask-on-div").mask("000.000.000-00");
  50.     $(".mask-on-div").fadeOut(500).fadeIn(500)
  51.   })
  52.  
  53.   $('pre').each(function(i, e) {hljs.highlightBlock(e)});
  54. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement