shaaa
shaaa

Reputation: 235

Regex to validate that the first letter of a word in input field is not a special character

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

Answers (3)

Bohemian
Bohemian

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

Sergey Kalinichenko
Sergey Kalinichenko

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.

Demo.

Upvotes: 2

Kiran Kumar
Kiran Kumar

Reputation: 1051

The ragex for special characters in the beginning is /^[$!@#%^&*(\-)_+=-\][{}|';,./?><:"]/g

Upvotes: -1

Related Questions