I tried this to disallow characters
<input type="text" id="full_name" name="full_name" ng-pattern="/[^\@\-#\-&]/">
but it's not working.
If you want to disallow @, #, &, and - characters, use "/^[^@#&-]*$/":
<input type="text" id="full_name" name="full_name" ng-model="YOUR_MODEL" ng-pattern="/^[^@#&-]*$/" />
The ^[^@#&-]*$ pattern matches:
^ - start of string[^@#&-]* - 0 or more chars other than the ones defined in the negated character class$ - end of string.Note: to make the value required, you may add required attribute, or replace the * quantifier in the pattern with + (to require at least 1 (or more) characters).
^@#&- means except these set of character. +1 for explainationHere a working example of ngPattern excluding @, #, &, and - characters with the use of Regular Expression: /^[^@#&-]+$/:
angular
.module('App', [])
.controller('ExampleController', function($scope) {
$scope.full_name = '';
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="App" ng-controller="ExampleController">
<form name="form">
<label for="full_name">This input is restricted by the current pattern: </label>
<input type="text" id="full_name" name="full_name" ng-model="full_name" ng-pattern="/^[^@#&-]+$/" /><br>
<hr>
Input valid? = <code>{{form.full_name.$valid}}</code><br>
Model value = <code>{{full_name}}</code>
</form>
</div>
@,#,&, and-? Then try"/^[^@#&-]*$/"ng-modelto your input:ngPatternadds the pattern validator tongModel