1
    <div class="form-group">
                                    <label class="col-md-4 control-label"><spring:message code="label.entity.PANNumber"></spring:message></label>
                                    <div class="col-md-7">
                                        <input type="text" class="form-control input-sm" 
                                            name="<spring:message code="label.PANNumber"></spring:message>" id="PANNumber"
                                            data-ng-model="manageCustomerObj.panNumber"  maxlength="10" />
                                    </div>
                                </div>

what should i have to add for allowing to PAN number in this(ABCDE1234F) format only ? i am using eclipse.

V.Ahlawat
  • 51
  • 1
  • 8

2 Answers2

0

first convert the string to uppercase and then check with following regex pattern

^[A-Z]{5}[0-9]{4}[A-Z]$

See this Example to use regex with ng-pattern

EDIT: For case insensitive search use ^[A-Za-z]{5}[0-9]{4}[A-Za-z]$

See Demo For Case Insesitive search

See Demo For Case sesitive search

Community
  • 1
  • 1
Atal Kishore
  • 4,480
  • 3
  • 18
  • 27
  • i added only ng-pattern="^[A-Z]{5}[0-9]{4}[A-Z]$" after maxlength="10".....its not working. – V.Ahlawat Oct 14 '16 at 05:49
  • on keyup event call a function where you verify this regex pattern and if it does not match show the error or if you want to use ng-pattern see this answer `http://stackoverflow.com/questions/19827570/validate-natural-input-number-with-ngpattern` – Atal Kishore Oct 14 '16 at 05:52
  • there is no keyup event. – V.Ahlawat Oct 14 '16 at 06:11
  • use `ng-change="myFunc()"` – Atal Kishore Oct 14 '16 at 06:16
  • i want to save my page with either pin_no is in correct format(AAAAA1111A) or empty...if we enter the incorrect format than it would show error msg “enter right pin”. – V.Ahlawat Oct 14 '16 at 11:21
0

try this

ng-pattern="/^[a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}$/"

edit: added {1} to last, now check and let me know

mahendra kamble
  • 1,375
  • 1
  • 14
  • 24
  • what error occured??and how you'r trying? will you plz post your code with keyup event also until what you tried now? – mahendra kamble Oct 14 '16 at 06:15
  • it takes albhabets/numbers/special character everything.......i did only that i added yr code after maxlength="10" in my code. and alphabets are in small letters – V.Ahlawat Oct 14 '16 at 06:21
  • if want only upper letters in your pan than you can use this `ng-pattern="/^[A-Z]{5}[0-9]{4}[A-Z]{1}$/"` – mahendra kamble Oct 14 '16 at 06:30
  • its also not working it shows also in small letters and not in specified pattern – V.Ahlawat Oct 14 '16 at 06:36
  • plz post your all code with respect to pan validation – mahendra kamble Oct 14 '16 at 06:57
  • i want to save my page with either pin_no is in correct format(AAAAA1111A) or empty...if we enter the incorrect format than it would show error msg “enter right pin”. – V.Ahlawat Oct 14 '16 at 11:25
  • yeah but post your all code related to PAN validation. – mahendra kamble Oct 14 '16 at 11:29
  • $scope.validatePanNo = function(PAN){ if(PAN!="") { if($scope.manageCustomerObj.panNumber!= /(^([a-zA-Z]{5})([0-9]{4})([a-zA-Z]{1})$)/) { logger.logError("Please enter PAN in format only !!"); } }; } – V.Ahlawat Oct 17 '16 at 12:35