Issue
I want to make progressive regex of PAN number.
My PAN number regular expression is "/^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}$/"
Format of PAN number -'AAAAADDDDA' A- Alphabets, D- Digits
Why I want to make progressive regex?
I am using angular directive to set validations on input field. In that I am facing problem to my PAN regex but it works fine for progressive regex. Check here my plunker
Referred question angularjs validate input and prevent change if invalid
Can any one please suggest me how to do this?
Thank you.
Solution
I think this should help you :
regexp = /^([a-zA-Z]([a-zA-Z]([a-zA-Z]([a-zA-Z]([a-zA-Z]([0-9]([0-9]([0-9]([0-9]([a-zA-Z])?)?)?)?)?)?)?)?)?)?$/;
Because you progressively want to test the regex, that's why it test the input letter by letter. ([a-zA-Z]){5}
<- this meant it needs 5 letters (all at same time) because you were testing for every letter input that's why it did not work.
For example :
AAAAA1111A
is correct according to your regex but
AAAAA1111
or AAAAA111
or AAAAA11
or AAAAA1
etc are not, that's why your regex did not allow the input!
http://plnkr.co/edit/x9x1ZT4InGHHo2f2ZL8f?p=preview
Answered By - Himanshu Tyagi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.