How to allow only alphanumeric use of ng-pattern-limit only for the first character?

I use https://github.com/AlphaGit/ng-pattern-restrict to limit input. What I'm trying to do is just the alphanumeric value for the first character ONLY. The problem is that I am using:

ng-pattern-restrict="^[a-zA-Z0-9]+"

it works, but will not allow the user to clear the entire line, which I will also like as an option.

+5
source share
3 answers

Refresh the regex to check for an empty script. Example below:

 ^$|^[A-Za-z0-9]+ 

Plunker

+5
source

This pattern allows at least one alphabet and one numeric value, but does not allow the creation of special characters.

 ng-pattern="/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/" 
0
source

This expression will help in clearing the input, and also does not allow the appearance of a character at the input in any position: ng-pattern-restrict="^$|^[A-Za-z0-9]+$"

0
source

All Articles