Reputation: 14419
I'm using https://github.com/AlphaGit/ng-pattern-restrict to restrict input. What I"m trying to do is only allow alphanumeric for the first character ONLY. The problem is if I use :
ng-pattern-restrict="^[a-zA-Z0-9]+"
it works, but won't allow user to clear the whole string, which I would also like as an option.
Upvotes: 8
Views: 30157
Reputation: 1064
ng-pattern-restrict="^([A-Za-z0-9]{0,})$"
This will allow only alhpanumeric values.
Upvotes: 1
Reputation: 1
This expression will help in clearing the input as well not allow any spcial character in the input at any position : ng-pattern-restrict="^$|^[A-Za-z0-9]+$"
Upvotes: 0
Reputation: 489
This pattern allows at least one alphabets and one numeric value but does not allows any special characters.
ng-pattern="/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/"
Upvotes: 0