Search code examples
angularjsregexpattern-matchingng-pattern

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.


Solution

  • 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.