How to enable to insert spaces in masked input plugin (JQuery Plugin)?
13,180
Solution 1
In case if you use http://github.com/RobinHerbots/jquery.inputmask , you can create your own mask:
$.extend($.inputmask.defaults.definitions, {
'A': {
validator: "[A-Za-z0-9 ]",
cardinality: 1
}
});
$("#field").inputmask("AAA");
If you use http://plugins.jquery.com/maskedinput/ , you create you mask like this:
$.mask.definitions['A'] = "[A-Za-z0-9 ]";
$("#field").mask("AAA");
Solution 2
you can change .mask and simply give space after *
//following script available in jquery.maskedinput.js
$.mask = {
//Predefined character definitions
definitions: {
'9': "[0-9]",
'a': "[A-Za-z]",
'*': "[A-Za-z0-9]"
},
dataName: "rawMaskFn",
placeholder: '_',
};
// if all ,then put *,if only number then put 9,if only alpha then put a
check this:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/jquery.maskedinput/1.3.1/jquery.maskedinput.js"></script>
<script>
jQuery(function($)
{
$.mask.definitions['~']='[+-]';
$('#Cell').mask('(* **)-(99 9) (a aa)');
});
</script>
http://jsfiddle.net/2Xz8q/1/ http://jsfiddle.net/2Xz8q/2/
Author by
user3655719
Updated on August 24, 2022Comments
-
user3655719 almost 2 years
I use masked input plugin, but it forbid enter spaces. * - Represents an alphanumeric character (A-Z,a-z,0-9), but not allow space-symbol
-
Andrew Prock over 6 yearsWelcome to Stack Overflow! Please write your answer in English, since Stack Overflow is an English site.