1

I am trying to validate phone number with RegEx. Below is my requirement. 10 Digits alpha/numeric, where an Alpha CHAR is in the 4th position (not including hyphen). For example: 586R410056

NNN ANN NNNN
(NNN) ANN NNNN
NNN-ANN-NNNN
(NNN) ANN-NNNN
1NNN ANN NNNN
1(NNN) ANN NNNN
1NNN-ANN-NNNN
1(NNN) ANN-NNNN
NNN.ANN.NNNN
(NNN-ANN-NNNN)

I came up with following RegEx, but it's not working in AngularJS form. RegEx:

^[1]?\s?\(?\d{3}\)?[-.\s]?[a-zA-Z]{1}\d{2}[-.\s]?\d{4}\)?$

Here is the plunker

2

1 Answer 1

1

Use this code:: DEMO

  <form class="form-inline container-fluid" name="userForm" novalidate>
    <div class="form-group">
      <input type="text" class="form-control" ng-model="addBTNWTNModalCotroller.selectedItem.lecBtn" ng-pattern="/^1?\s?\(?\d{3}\)?[-.\s]?[a-zA-Z]\d{2}[-.\s]?\d{4}\)?$/" ng-change="addBTNWTNModalCotroller.onBtnFieldChange()" name="btn" required style="width: 90%;"
      placeholder="Enter here..."> 
      <div ng-show="userForm.btn.$touched">
        <span class="error-text" ng-show="userForm.btn.$error.required">
                  <span class="icon-ICON_WARNING"></span> BTN is required.
        </span>
        <span class="error-text" ng-show="userForm.btn.$error.pattern">
                   <span class="icon-ICON_WARNING"></span> Please enter valid BTN.
        </span>
      </div>
    </div>
  </form>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.