我想在接受這三個言AngularJs使用正則表達式數字表達式:經常在AngularJs
09344542525 -> 11 length integer that start with 09
02144532363 -> 11 length integer that start with 021
44532363 -> 8 length integer
這裏是我的HTML:
<div class="container co-operate" ng-controller="cooperationController">
<form novalidate name="cooperationForm" class="signinform">
<div class="form-group inner-addon right-inner-addon">
<label class="form-label control-label"></label>
<input ng-model="restaurantInformation.tel" type="text" name="tel" id="tel" placeholder="phone number"
ng-pattern="mobRegEx || prePhoneRegEx || phoneRegEx" class="form-control default-input singleline-input" required />
<span class="form-icon icon icon-avatar"></span>
</div>
<p ng-show="cooperationForm.tel.$error.pattern" style="color: red">Wrong number format</p>
</form>
</div>
角:
app.controller('cooperationController', function ($scope) {
$scope.mobRegEx = '/09[0-3][0-9]{8}/';
$scope.prePhoneRegEx = '/021[0-9]{8}/';
$scope.phoneRegEx = '[0-9]{8}';
.
.
.
}
其實,當我的輸入很髒並且我測試了整數時,錯誤段落總是顯示錯誤。
任何修改正則表達式的建議?
神話般的答案,謝謝你馬里亞諾 – AFN