Reputation: 235
I am using angularjs. I want to use validation for my name field. I am a beginner in regex expressions. I want that the first letter of the name is not a special Character. For E.g My$Repo should be valid and $MyRepo is invalid.
I am using ng-pattern to validate the name field. What regex expression should i use? Appreciate your help.
Upvotes: 2
Views: 1957
Reputation: 425023
There are lots of "special" characters, but few "non-special"; I would specify what is allowed:
^[a-zA-Z].*
This means "any Latin letter followed by anything".
To allow letters from any alphabet:
^\p{L}.*
This means "any letter from any alphabet followed by anything".
Upvotes: 1
Reputation: 726569
You can use ^\w.*$
, which means "a string of at least one character, with the initial character that is a letter from Latin alphabet, a digit, or an underscore.
Upvotes: 2
Reputation: 1051
The ragex for special characters in the beginning is /^[$!@#%^&*(\-)_+=-\][{}|';,./?><:"]/g
Upvotes: -1