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/;