Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-pattern allow only letters, numbers, dot, underscore and dash

How'd allow for an input using ng-pattern only: letters, numbers, dot, underscore and dash ( . _ -)?

Already tried the following ones

UPDATE:

$scope.validationPattern = '/^[a-zA-Z\d\-\_]+$/';

<input ng-model="model" type="text" ng-pattern="{{validationPattern}}" />
like image 817
el.severo Avatar asked Aug 24 '16 11:08

el.severo


1 Answers

Judging by your requirements, you need to add a dot to the pattern:

$scope.regex = '^[a-zA-Z0-9._-]+$';

and add ng-trim="false" to the <input> tag so as to disallow leading/trailing spaces.

See this plunkr

like image 114
Wiktor Stribiżew Avatar answered Oct 10 '22 15:10

Wiktor Stribiżew