assisrafael/angular-input-masks

Match regex before applying mask

Open

#63 创建于 2015年3月15日

在 GitHub 查看
 (0 评论) (0 反应) (0 负责人)JavaScript (970 star) (334 fork)batch import
enhancementhelp wanted

描述

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

贡献者指南