assisrafael / assisrafael/angular-input-masks

Match regex before applying mask

Open
#63 0 comments 0 reactions 0 assignees View on GitHub
enhancement help wanted
Dominant language
JavaScript
Stars
955
Forks
329
PR merge metrics
No merged PRs in 30d

Description

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 `` 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
##

---
Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/9576006-match-regex-before-applying-mask?utm_campaign=plugin&utm_content=tracker%2F1022469&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F1022469&utm_medium=issues&utm_source=github).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.