Angularjs regex case insensitive modifier not working

638 views
Skip to first unread message

Sam

unread,
Jan 8, 2017, 3:24:44 PM1/8/17
to Angular

I am trying to use the below Email Address pattern in http://www.regular-expressions.info/email.html

\A[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\z

My code:

<input type="email" name="email" ng-model="email" ng-pattern="/^[a-z0-9!#$%&amp;'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&amp;'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/" id="email-1" value="" required="" class="ng-pristine ng-untouched ng-empty ng-valid-email ng-invalid ng-invalid-required ng-valid-pattern">

This is case sensitive.


I tried using 'i' modifier.

"/^[a-z0-9!#$%&amp;'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&amp;'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i"

However, it still wouldn't accept capitalized character (shows invalid email error message).


I came across https://github.com/angular/angular.js/issues/1437. However, I am using a later version (1.2).


I also tried A-Z, no luck with that either.

"/^[A-Za-z0-9!#$%&amp;'*+\/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#$%&amp;'*+\/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/"

How to make this pattern case insensitive?

Thank you for your help.

Sander Elias

unread,
Jan 8, 2017, 11:13:19 PM1/8/17
to Angular
Hi Sam,

The $i modifier does indeed not work in the 1.2 branch. You might consider backporting the fix for that to 1.2, and put in a PR for that.
However, adapting the regex, with A-Z does work for me, as you can see working in this plunk.

This is what works:     
 <input type="email" name="email" ng-model="vm.email" ng-pattern="/^[A-Za-z0-9!#$%&amp;'*+\/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#$%&amp;'*+\/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/" id="email-1" value="" required="">

(I worked it in from your original code, didn't diff it with your A-Z version.)

Regards
Sander

Reply all
Reply to author
Forward
0 new messages