javascript - 10 digit Regex Validation with angularJs ng-Pattern - Stack Overflow

I want one of my input fields to have exactly 10 digits. I have used ng-pattern in following manner<

I want one of my input fields to have exactly 10 digits. I have used ng-pattern in following manner

<input type="text" ng-pattern="/[1-9]{1}[0-9]{9}$/" ng-model="user.Identity" name="identity">

The problem is that this expression is allowing the user to enter numeric strings having more than 10 digits whereas, I want to allow exactly 10 digits. Is there a problem with my regex or my understanding of ng-pattern?

I want one of my input fields to have exactly 10 digits. I have used ng-pattern in following manner

<input type="text" ng-pattern="/[1-9]{1}[0-9]{9}$/" ng-model="user.Identity" name="identity">

The problem is that this expression is allowing the user to enter numeric strings having more than 10 digits whereas, I want to allow exactly 10 digits. Is there a problem with my regex or my understanding of ng-pattern?

Share asked Mar 24, 2015 at 14:55 Muhammad Adeel ZahidMuhammad Adeel Zahid 17.8k16 gold badges94 silver badges159 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

The ^ anchor indicates start of string/line as $ does for the end, ^expr$ prevents the shifting window matches you see:

/^[1-9]{1}[0-9]{9}$/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742400665a4436845.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信