# Variable maxlengthDirective`Const`

maxlengthDirective: (string | (($parse: ParseService) => Directive))[] = ...

#### Type declaration

- string
- ($parse: ParseService) => Directive
  - - ($parse: ParseService): Directive

    - #### Parameters

      - $parse: ParseService

      #### Returns Directive

#### Param: ngMaxlength

AngularTS expression that must evaluate to a `Number` or `String` parsable into a `Number`. Used as value for the `maxlength` ngModel.NgModelController#$validators validator.

#### Description

ngMaxlength adds the maxlength ngModel.NgModelController#$validators `validator` to ngModel `ngModel`. It is most often used for text-based input `input` controls, but can also be applied to custom text-based controls.

The validator sets the `maxlength` error key if the ngModel.NgModelController#$viewValue `ngModel.$viewValue` is longer than the integer obtained by evaluating the AngularTS expression given in the `ngMaxlength` attribute value.

**Note:** This directive is also added when the plain `maxlength` attribute is used, with two differences:

1. `ngMaxlength` does not set the `maxlength` attribute and therefore HTML5 constraint validation is not available.
2. The `ngMaxlength` attribute must be an expression, while the `maxlength` value must be interpolated.

- Defined in src/directive/validators/validators.js:220