angular.validator.regexp

Work in Progress This page is currently being revised. It might be incomplete or contain inaccuracies.

Description

Use regexp validator to restrict the input to any Regular Expression.

Usage

In HTML Template Binding

<input type="text" ng:validate="regexp:expression[:msg]"/>

In JavaScript

angular.validator.regexp(value, expression[, msg])

Parameters

Example

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