简体   繁体   中英

angulajs ng-pattern validator for input field

I am working with angularjs form validations, where i have few fields need to validate them, i will only allow the user to enter input starting with certain mix of characters and numbers(will be 7 after characters)like BID0001234, Q0001234 and PO0001234. In this case(BID0001234) i have tried these patterns '^BID/[0-9\\d] $/','^BID/^[0-9\\d] $/' and '^BID/^[0-9\\d]+$/'. for some reason unable to validate it, could you someone please share the experience or direct me towards a regex pattern link that matches my issue.

update: I want to count the numbers after the BID as well, seven numbers are accepted

Plunker

Any help is much appreciated

No need for the slashes. Try

ng-pattern="'^BID[0-9]+$'"

For exactly seven digits after "BID":

ng-pattern="'^BID[0-9]{7}$'"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM