Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow upper case letters when using jquery.inputmask

I'm using jquery.inputmask on a text box that is used to collect email addresses and I want to be able to type in upper case letters.

Currently, it converts any upper case letters as you type them to lower case. How can I change it to accept both upper and lower case letters.

JSFiddle:

$(document).ready(function(){
    //email mask 
    $("#u_email").inputmask({
        mask: "*{1,20}[.*{1,20}][.*{1,20}][.*{1,20}]@*{1,20}[.*{2,6}][.*{1,2}]",
        greedy: false,
        onBeforePaste: function (pastedValue, opts) {
            pastedValue = pastedValue.toLowerCase();
            return pastedValue.replace("mailto:", "");
        },
        definitions: {
            '*': {
                validator: "[0-9A-Za-z!#$%&'*+/=?^_`{|}~\-]",
                cardinality: 1,
                casing: "lower"
            }
        }
    });
});     
like image 351
Ronald McDonald Avatar asked Dec 06 '25 09:12

Ronald McDonald


1 Answers

From reading the inputmask jquery plugin documentation, there are two things forcing the text input contents to lower case.

The pastedValue = pastedValue.toLowerCase(); changes any copy-pasted text to lowercase.

The casing: "lower" changes any typed text to lowercase.

Removing both of these lines, we are left with the below, which works on your jsfiddle.

$(document).ready(function(){
     //email mask 
   $("#u_email").inputmask({
           mask: "*{1,20}[.*{1,20}][.*{1,20}][.*{1,20}]@*{1,20}[.*{2,6}][.*{1,2}]",
            greedy: false,
            onBeforePaste: function (pastedValue, opts) {
                return pastedValue.replace("mailto:", "");
            },
            definitions: {
                '*': {
                    validator: "[0-9A-Za-z!#$%&'*+/=?^_`{|}~\-]",
                    cardinality: 1
                }
            }
    });
});
like image 115
Matt Giltaji Avatar answered Dec 07 '25 22:12

Matt Giltaji



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!