jcadima
6/15/2015 - 6:01 PM

Input mask on common elements

Input mask on common elements

// ref: http://igorescobar.github.io/jQuery-Mask-Plugin/

// The HTML:
<input type="text" class="form-control" id="dob"  name="dob">


// script.js:
jQuery.noConflict();	
jQuery(document).ready(function() {
   jQuery("#dob").mask('00/00/0000');
});




// for Wordpress: 
function theme_js() {
	// ********* LOAD IN FOOTER
	wp_enqueue_script ('masked_js', get_template_directory_uri() . '/js/jquery.maskedinput.min.js', array('jquery'),'', true  ) ;
	wp_enqueue_script ('script_js', get_template_directory_uri() . '/js/scripts.js', true ) ;

}
add_action('wp_enqueue_scripts', 'theme_js') ;


// Basic Usage List:
$(document).ready(function(){
  $('.date').mask('00/00/0000');
  $('.time').mask('00:00:00');
  $('.date_time').mask('00/00/0000 00:00:00');
  $('.cep').mask('00000-000');
  $('.phone').mask('0000-0000');
  $('.phone_with_ddd').mask('(00) 0000-0000');
  $('.phone_us').mask('(000) 000-0000');
  $('.mixed').mask('AAA 000-S0S');
  $('.cpf').mask('000.000.000-00', {reverse: true});
  $('.money').mask('000.000.000.000.000,00', {reverse: true});
  $('.money2').mask("#.##0,00", {reverse: true});
  $('.ip_address').mask('0ZZ.0ZZ.0ZZ.0ZZ', {
    translation: {
      'Z': {
        pattern: /[0-9]/, optional: true
      }
    }
  });
  $('.ip_address').mask('099.099.099.099');
  $('.percent').mask('##0,00%', {reverse: true});
  $('.clear-if-not-match').mask("00/00/0000", {clearIfNotMatch: true});
  $('.placeholder').mask("00/00/0000", {placeholder: "__/__/____"});
  $('.fallback').mask("00r00r0000", {
      translation: {
        'r': {
          pattern: /[\/]/, 
          fallback: '/'
        }, 
        placeholder: "__/__/____"
      }
    });
  $('.selectonfocus').mask("00/00/0000", {selectOnFocus: true});
);