jqueryjquery-inputmask

Use jQuery Inputmask that allows only A-Z, a-z, 0-9 and spaces


I use Robin Herbots jQuery.Inputmask to restrict what my users are allowed to enter into textboxes, I've found that this jQuery plugin works rather well. I have a textbox on my form that I want to be able to restrict the input to only characters A-Z (upper and lowercase), spaces, and numbers. The documentation, located here, doesn't address this particular case and nothing I've attempted works neither does anything I've found online. My textbox code:

$(document).ready(function () {
    $("#<%=TextBox_DataFieldTitle.ClientID%>").inputmask("******************");
});

Any suggestions?


Solution

  • You can use the regex property:

    $("#in").inputmask({regex: "(\\w| )*"});
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/5.0.8/jquery.inputmask.min.js"></script>
    
    <input id="in">

    Side note: this library has an issue: it doesn't respond well to combination keys, like the ¨ key I have on my keyboard, which is intended to be combined with the next key stroke, like e in order to type ë.