Pattern that restricts user to enter special characters for first character

2.2k views Asked by At

I have a requirement for an input field that should allow numbers, alphabets, and special characters like #,$,%,^ etc. But with only one condition the first character that I enter in the text box should not be a special character.

Example:

  1. @Test123 --Invalid character
  2. Test@123 --Valid character
  3. T@est123% --Valid character

I tried this

ng-pattern="/^([a-zA-Z0-9]+)([a-zA-Z0-9 &()_+@&\-=\\|,.\/?\s]+)$/"

But not working.

1

There are 1 answers

1
Ram_T On BEST ANSWER

Try this one

ng-pattern="/^[a-zA-Z0-9]+[^]*$/"

[a-zA-Z0-9]+ means one of alphabet or number and

[^]* means everything