bucicimaci
bucicimaci

Reputation: 1341

Angular 2 Validator pattern

I tried to implement a pattern validator with a built in validator in angular. I wanted to use this patter: /\S+/g but it didn't work because angular overwrites my pattern in its function You can see it here Why do they put the ^ and a $ at the beginning and the end of the string? Should I use a custom validator instead the built in? Is it a bug or working as expected?

Here is a plunkrhttp://plnkr.co/edit/OHrUitqUnhIYxsraby7J

Upvotes: 1

Views: 1035

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627507

It seems that this validator does not allow a regex literal to be passed. You need to make sure you match the whole string. So, if you plan to require the string to have at least one non-whitespace character, use

".*\\S.*"

See the updated plunkr.

Upvotes: 2

Related Questions