angular-input-masks
angular-input-masks copied to clipboard
Match regex before applying mask
Check if the current $modelValue matches the desired mask, instead of forcefully removing all the non matching characters first.
Example: if I have an input with <input type="text" ui-br-cep-mask ng-model="user.data.cep"> and user.data.cep is "00000-000" (this is the $modelValue) don't try to change the $viewValue of it, or the input will become truncated because of these lines:
var formatedValue = processed.result;
return formatedValue.trim().replace(/[^0-9]$/, '');
Before this line, it's saying 00000- and that's not valid. It may be a bug.
The input will be set to 00000 instead of 00000-000 because of this. The same goes to all other directives (CPF, CNPJ, Date, etc)
IMHO an UI library shouldn't dictate the format of the data that goes into the database, the library should fit the data you provide to it. I always keep the format in the database, and would never store a mobile as an int like 11999999999 into the database