SoFunction
Updated on 2025-04-04

AngularJS form verification example (not required)

The code looks like this:

<form ng-app="myApp" ng-controller="validateCtrl" 
name="myForm" novalidate>

<p>Telephone:<br>
<input type="text" name="phone" ng-model="phone" ng-pattern="/(^$)|^(((\+86)|(86))?1[34578]\d{9})$/">
<span style="color:red" ng-show=".$dirty && .$invalid">
  联系Telephone格式不正确!</span>
</p>

<p>
<input type="submit"
ng-disabled="myForm.$invalid">
</p>
</form>

Regular expression:

1. Match empty: ^$

2. Match mobile phone number: ^(((\+86)|(86))?1[34578]\d{9})$

3. Control the display of prompt information: ng-show=".$dirty && .$invalid"

The above example of AngularJS form verification mobile phone number (not required) is all the content I share with you. I hope you can give you a reference and I hope you can support me more.