JQuery Mask Plugin

by crismahe

HTML

<script src="http://igorescobar.github.io/jQuery-Mask-Plugin/js/jquery.mask.min.js"></script>
<input id="hours" type="text" value="" name="hours" >
    
<!--  http://igorescobar.github.io/jQuery-Mask-Plugin/   -->

JavaScript

var options_hours = {
    'translation': {
        3: {
            pattern: /[0-2*]/,
            optional: true
        },
        4: {
            pattern: /[0-4*]/
        }
    }, 
   
    onKeyPress: function (cep) {

        var masks = ['30', '24'];
        if (cep.length > 1) {
            var first_number = cep.substring(0, 1);
        } else {
            var first_number = "";
        }
       
        mask = (first_number == '2') ? masks[1] : masks[0];
                
        $('#hours').mask(mask, this);
    }
};

$('#hours').mask('30', options_hours);