Skip to main content

angualrs angulars js client side validation on phone number unable to combine regex foramtsformats

The following formats are allowed for the phone number

  1. xxx-xxx-xxxx [x represents a digit]
  2. xxx.xxx.xxxx
  3. xxxxxxxxxx [digit ten times]

I have the working sample for the formats but I am unable to combine them in a single regex help me. How to combine them into a single regex?

  1. "/^[1-9]\d{2}-\d{3}-\d{4}|^\d{10}$/"

    "/^[1-9]\d{2}-\d{3}-\d{4}|^\d{10}$/"
  2. "/^[1-9]\d{2}[.]\d{3}[.]\d{4}|^\d{10}$/"

    "/^[1-9]\d{2}[.]\d{3}[.]\d{4}|^\d{10}$/"
  3. "/^\d{10}$/" my regex code in angular

    {{'PHONE'|translate }} Please enter phone number "/^\d{10}$/"

My regex code in angular:

<div class="form-group" ng-class="{'has-error':userprofileForm.phone.$touched && userprofileForm.phone.$invalid && userprofileForm.extension.$touched && userprofileForm.extension.$invalid}">
   <label for="profile-phone" class="control-label">{{'PHONE'|translate }}</label>
    <div>
       <input name="phone" type="text" class="form-control" ng-model="userprofile.phoneNumber" ng-pattern="/^\d{10}$/" required="required" />
       <div ng-show="userprofileForm.phone.$touched && userprofileForm.phone.$invalid">    
          <span ng-message="required">Please enter phone number</span>
        </div>
    </div>
</div>

angualrs js client side validation on phone number unable to combine regex foramts

The following formats are allowed for the phone number

  1. xxx-xxx-xxxx [x represents a digit]
  2. xxx.xxx.xxxx
  3. xxxxxxxxxx [digit ten times]

I have the working sample for the formats but unable to combine them in a single regex help me combine them into single regex

  1. "/^[1-9]\d{2}-\d{3}-\d{4}|^\d{10}$/"

  2. "/^[1-9]\d{2}[.]\d{3}[.]\d{4}|^\d{10}$/"

  3. "/^\d{10}$/" my regex code in angular

    {{'PHONE'|translate }} Please enter phone number

angulars js client side validation on phone number unable to combine regex formats

The following formats are allowed for the phone number

  1. xxx-xxx-xxxx [x represents a digit]
  2. xxx.xxx.xxxx
  3. xxxxxxxxxx [digit ten times]

I have the working sample for the formats but I am unable to combine them in a single regex. How to combine them into a single regex?

  1. "/^[1-9]\d{2}-\d{3}-\d{4}|^\d{10}$/"
  2. "/^[1-9]\d{2}[.]\d{3}[.]\d{4}|^\d{10}$/"
  3. "/^\d{10}$/"

My regex code in angular:

<div class="form-group" ng-class="{'has-error':userprofileForm.phone.$touched && userprofileForm.phone.$invalid && userprofileForm.extension.$touched && userprofileForm.extension.$invalid}">
   <label for="profile-phone" class="control-label">{{'PHONE'|translate }}</label>
    <div>
       <input name="phone" type="text" class="form-control" ng-model="userprofile.phoneNumber" ng-pattern="/^\d{10}$/" required="required" />
       <div ng-show="userprofileForm.phone.$touched && userprofileForm.phone.$invalid">    
          <span ng-message="required">Please enter phone number</span>
        </div>
    </div>
</div>
Source Link
arvind
  • 8.8k
  • 1
  • 15
  • 5

angualrs js client side validation on phone number unable to combine regex foramts

The following formats are allowed for the phone number

  1. xxx-xxx-xxxx [x represents a digit]
  2. xxx.xxx.xxxx
  3. xxxxxxxxxx [digit ten times]

I have the working sample for the formats but unable to combine them in a single regex help me combine them into single regex

  1. "/^[1-9]\d{2}-\d{3}-\d{4}|^\d{10}$/"

  2. "/^[1-9]\d{2}[.]\d{3}[.]\d{4}|^\d{10}$/"

  3. "/^\d{10}$/" my regex code in angular

    {{'PHONE'|translate }} Please enter phone number