2015-12-21 112 views
0

我試圖讓以下條件成正則表達式:正則表達式條件

-The第一條件是用戶不能在第一個數字,當用戶輸入「0」時,錯誤消息「錯誤格式編號「0」插入「會顯示

第二種情況是用戶只能輸入9位數字和數字。當用戶輸入數字小於9時,會顯示錯誤信息」輸入9位數字「。

這是我當前的代碼:

<form ng-submit="okPhoneAction(phonePopUp, prompt.phoneNumber)" name="phonePopUp" novalidate> 
    <div class="popupBodyNav"> 
     <p>Please enter your phone number</p> 
     <label class="item item-input down" style="padding-left: 5px; width: 80%; margin-left: 10%;"> 
      <i class="placeholder-icon" style="font-size: 14px;">+971</i> 
     <input ng-model-options="{ updateOn: 'blur' }" type="tel" pattern="[0-9]*" id="phoneNumber" name="phoneNumber" ng-minlength="9" maxlength="9" ng-model="prompt.phoneNumber" ng-pattern="/^\d{1,15}(\.\d{1,15})?$/" required/> 

     </label> 
     <div class="error-container text-left" ng-show="phonePopUp.phoneNumber.$invalid && phonePopUp.phoneNumber.$dirty"> 
      <p ng-if="phonePopUp.phoneNumber.$error.required " class="help-block validatext-pop" style="font-size: 12px" translate="VALIDATION.required">Phone number can not be empty</p> 
      <p ng-if="phonePopUp.phoneNumber.$error.minlength" class="help-block validatext-pop" style="font-size: 12px" translate="VALIDATION.mobileNumber">input 9 digits number</p> 
      <p ng-if="phonePopUp.phoneNumber.$error.pattern" class="help-block validatext-pop" style="font-size: 12px; color: #fff !important;" translate="VALIDATION.antiZero">wrong format</p> 
     </div> 
    </div> 
    <div class="popupBottomNav"> 
     <div class="halfBottomNav"> 
      <input type="submit" class="buttonWhite" value="Cancel" ng-click="closePromtPhone()" /> 
     </div> 
     <div class="halfBottomNav"> 
      <input type="submit" class="buttonWhite" value="OK" /> 
     </div> 
    </div> 
</form> 

你可以幫我修復代碼? - 謝謝

+3

嘗試'[1-9] [0-9] {8}' – Tushar

+1

作爲@Tushar說,但加^和$/^ [1-9] [0-9] {8} $ /拒絕字符串asd999999999 – Polak

+0

好的,謝謝你們, 並知道如何做出條件,所以如果用戶輸入「0」會調用錯誤信息「錯誤的格式」將顯示,但如果用戶輸入號碼小於9的錯誤信息將調用錯誤信息「輸入9位數字「? – Alver

回答

0

如果您正在設置檢查一個標準的10位電話號碼配置,然後試試這個。

"/^[1-9]{1}-[0-9]{3}-[0-9]{3}-[0-9]{4}$/"