0

I have an issue with Validators.pattern with a following regex:

/^[_a-z0-9]+([_a-z0-9]+)*@[a-z0-9-]+([a-z0-9-]+)*([a-z]{2,4})$/

which should verify email address. You can check out the plnkr. If you delete Validators.pattern(..), the form will work.

Any ideas?

2 Answers 2

1

Probably because pattern wasn't yet avaliable in beta.37 which you're using in your Plunker.

ORIGINAL EXCEPTION: TypeError: angular2_1.Validators.pattern is not a function

Working Plunker

Sign up to request clarification or add additional context in comments.

6 Comments

Good eyes! However, in my project I use the newest beta, and still have the same issue. I will update the plnkr in a few
I added a link to a Plunker. I changed a few things. I think you need to use ` (backtick) instead of " and no / around the regexp.
this theoretically works, but it will always give a form "INVALID" like here plnkr.co/edit/W7wiBKgkIKecS2wpXaQ1?p=preview
I'mm not using TypeScript or JS myself (only Dart). Maybe the ` isn't the right way to wrap the regex. I just checked it doesn't produce an error and the form value is shown.
` seems to be fine. " requires $ to be escaped as \$. The problem is probably the email regex. It works fine with simpler regex or when the the email doesn't contain a . like abc@def but [email protected] is shown as invalid.
|
1

Why not use the built-in email validation:

<input name="myInput" ng-model="myInput" type="email">

See http://www.w3schools.com/angular/angular_validation.asp

1 Comment

in angular2 ng-model should be [(ngModel)]

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.