Reputation: 2287
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}}" />
Upvotes: 5
Views: 31225
Reputation: 2465
/^[a-zA-Z0-9 ._-]+$/
This regex seems appropriate enough for you if it don't directly fit in ng-pattern make necessary adjustments, like.
in controller add
$scope.pattern = /^[a-zA-Z0-9 ._-]+$/;
now in html use ng-pattern="pattern"
Tested using this : http://www.regextester.com/
Accepts numbers, alphabets and three symbols(.-_)
Upvotes: 2
Reputation: 627380
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
Upvotes: 13