A simple, pure AngularJS directive to restricts the characters that may be entered into a text field.
Install using Bower:
# install package and add it to bower.json dependencies
$ bower install angular-nghalt --saveInclude the script and style:
<script src="bower_modules/angular-nghalt/src/ng-hide.js"></script>Include the ngHalt dependency on your Angular module:
angular.module('demoApp', ['ngHalt']);For alpha
<input type="text" ng-halt="alpha: true">For alphanumeric
<input type="text" ng-halt="alpha: true,numeric:true">For alphanumeric + special characters
<input type="text" ng-halt="alpha: true,numeric:true ,special:true">AllowSpace
<input type="text" ng-halt="alpha: true,numeric:true ,special:true,allowSpace:true">To pass custom regex
<input type="text" ng-halt="regex:^[A-Za-z]*$">Pass a string to ng-halt like this: ng-halt="alpha: true, special: false"
| Option | Default | Description |
|---|---|---|
| alpha | true | Can accept alphabet(A-Za-z). |
| numeric | true | Can accept Number(0-9). |
| special | true | Can accept non-word character |
| maxlength | false | Check maximum length. Defaults to 50. |
| allowSpace | true | Can accept space. |
| regex | false | Pass a custom regex to restrict user from input. |