AngularJS Built-in directives ngPattern

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

The ng-pattern directive accepts an expression that evaluates to a regular expression pattern and uses that pattern to validate a textual input.

Example:

Lets say we want an <input> element to become valid when it's value (ng-model) is a valid IP address.

Template:

<input type="text" ng-model="ipAddr" ng-pattern="ipRegex" name="ip" required>

Controller:

$scope.ipRegex = /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/;


Got any AngularJS Question?