# 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

- `value – {string} –`

  value to validate

- `expression – {string|regexp} –`

  regular expression.

- `msg(optional) – {string} –`

  error message to display.

## 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.attr('className')).not().toMatch(/ng-validation-error/);
       expect(textBox.val()).toEqual('123-45-6789');
       input('ssn').enter('123-45-67890');
       expect(textBox.attr('className')).toMatch(/ng-validation-error/);
      });