Regular expression starting with letter only not working

I have the following JSFiddle where I am able to restrict the validation to numbers, characters, no spaces and underscores using this : regexp: /^[A-Za-z0-9_]+$/.

However, I want to start it using letter only and not with number or special character or anything else. I tried this: regexp: /^[a-zA-Z]+[A-Za-z0-9_]+$/, but it doesn’t work.

What am I doing wrong here?

Leave out the first + sign between the first character in the string and the others.


I tried it here :

Can you tell me why it is showing me this error messageYou can introduce just alphabetical characters, underscore, number but no spaces when I type first letter as some letter? I was expecting that this will only show up if I start with number but it’s doing it with letters as well.

If you enter a single alpha character and then test, as you are doing, the regex fails as it is looking for more characters after the first one. If you continue typing the error message goes away as the regex is satisfied.
If you type an invalid first character the error message will remain as the regex fails on the first character.

Okay, so it is behaving correctly ?

I tested some test cases like 1) 1abcdefghi and the error stayed there. However, testing 2) abcdefghi didn’t throw any error. I think it’s the minimum 4 character limit and that’s the reason it shows error at the start.

Yes, there is a 4-character minimum and a 10 character maximum, which I guess you set up.
You can avoid the error display at the start if you only test the string once it is completed, which means not checking every character as it is typed.

Ok, Thanks for your valuable inputs. Appreciated!