Reputation: 584
I have added a maskDefinition on ui-mask and it is working great except it only allows me to enter one character in the input box. I need to be able to enter many characters.
This is the maskDefinition (the asterix in there is my attempt to permit many characters. The result is the same with or without the asterix.)
'N': /^[a-zA-Z0-9-' ]*$/
This is how I use it:
<input data-ng-model="demogItems.firstName" ui-mask="N" name="firstName" data-ng-required="true" />
It works great allowing upper and lower case letters, numbers, and 3 special characters (hyphen, apostrophe, and space) and no other special characters. But it only allows one of any of those. Also, the requirement is that the characters are allowed or not allowed, onKeyUp, not on onBlur.
How do I get this maskDefinition to allow many characters?
Upvotes: 0
Views: 686
Reputation: 21
Each token in maskDefinition
needs to match a single character in the input field. So you cannot use '*'
in the regex for your 'N'
token, as that would match multiple characters.
Since you want to be able to input a variable number of characters, you must set ui-mask
to something like '?N?N?N?N?N'
(repeat '?N'
for as many maximum characters you would like to accept).
It's an ugly solution, but I could not find a better one with ui-mask.
I suggest you take a look at ui-number-mask instead. It has it's limitations as well, but it may suit you better.
Upvotes: 1