Use regexp validator to restrict the input to any Regular Expression.
<input type="text" ng:validate="regexp:expression[:msg]"/>
angular.validator.regexp(value, expression[, msg])
value – {string} –
value to validate
expression – {string|regexp} –
regular expression.
msg(optional) – {string} –
error message to display.
<script> function Cntl(){ this.ssnRegExp = /^\d\d\d-\d\d-\d\d\d\d$/; } </script> Enter valid SSN: <div ng:controller="Cntl"> <input name="ssn" value="123-45-6789" ng:validate="regexp:ssnRegExp" > </div>
it('should invalidate non ssn', function(){ var textBox = element('.doc-example-live :input'); expect(textBox.prop('className')).not().toMatch(/ng-validation-error/); expect(textBox.val()).toEqual('123-45-6789'); input('ssn').enter('123-45-67890'); expect(textBox.prop('className')).toMatch(/ng-validation-error/); });