2016-11-04 11 views
0

ための角度JSの検証は誰が電話番号の検証で私を助けることができるとEメールEメールおよび電話番号

<div class="form-group" ng-if="notificationMethod == 'call' || notificationMethod == 'text'" > 
                <label for="phoneNumber">Phone Number</label> 
                <input type="phoneNumber" class="form-control" id="phoneNumber" placeholder="Enter Phone Number" ng-model="phoneNumberToBeNotified" ng-minlength="10" ng-maxlength="10" ng-pattern="^\d{4}-\d{3}-\d{4}$" required/> 
                <!-- <span class="error" style="color:#ff0000;" ng-show="myForm.phoneNumber.$error.required"> This field is required </span> 
                <span class="error" style="color:#ff0000;" ng-show="myForm.phoneNumber.$error.minlength"> Mobile number should be of 10 digits </span><br> 
                <span class="error" style="color:#ff0000;" ng-show="myForm.phoneNumber.$error.minlength"> Mobile number should be of 10 digits </span> --> 
               </div> 
               <div class="form-group" ng-if="notificationMethod == 'email'"> 
                <label for="email">E-Mail</label> 
                <input type="email" class="form-control" name="email" placeholder="Enter Email" ng-model="emailToBeNotified" required/> 
                <span ng-show="myForm.email.$error.required"> This field is required </span> 
                <span ng-show="myForm.email.$error.email"> Not a valid email </span> 
               </div> 

答えて

0

この記事

Validate phone number using angular js

を参照してください。
<input type="number" 
        class="form-control" 
        ng-minlength="10" 
        ng-maxlength="10" 
        id="inputPhone" 
        name="phone" 
        placeholder="Phone" 
        ng-model="user.phone" 
        ng-required="true"> 
      <span class="help-block" 
        ng-show="registration.phone.$error.required || 
          registration.phone.$error.number"> 
          Valid phone number is required 
      </span> 
      <span class="help-block" 
        ng-show="((registration.phone.$error.minlength || 
          registration.phone.$error.maxlength) && 
          registration.phone.$dirty) "> 
          phone number should be 10 digits 
      </span> 

OR

あなたの検証パターン(ph_numbr)

<form class="form-horizontal" role="form" method="post" name="registration" novalidate> 
    <div class="form-group" ng-class="{ 'has-error' : (registration.phone.$invalid || registration.phone.$pristine)}"> 
    <label for="inputPhone" class="col-sm-3 control-label">Phone :</label> 
    <div class="col-sm-9"> 
     <input type="number" class="form-control" ng-pattern="ph_numbr" id="inputPhone" name="phone" placeholder="Phone" ng-model="user.phone" ng-required="true"> 
     <div class="help-block" ng-messages="registration.phone.$error"> 
     <p ng-message="required">Phone number is required.</p> 
     <p ng-message="pattern">Phone number is invalid.</p> 
     </div> 
    </div> 
    </div> 
</form> 
0

もEメールの検証が含まれている非常に良いアンギュラフォーム検証例であるhttp://plnkr.co/edit/lCRwhj?p=preview電話番号の検証のための

<div class="form-group" ng-class="{ 'has-error' : userForm.email.$invalid && !userForm.email.$pristine }"> 
     <label>Email</label> 
     <input type="email" name="email" class="form-control" ng-model="user.email"> 
     <p ng-show="userForm.email.$invalid && !userForm.email.$pristine" class="help-block">Enter a valid email.</p> 
    </div> 
+0

を追加するには、電話番号の検証で私を助けることができますか? –

関連する問題