I am trying to create a javascript regex for below conditions
I have created a regex ^(?![0-9]|[_].*$).*
which will work for last two conditions above. Please suggest how can I add an and
condition to make it work for all above scenarios.
You may use the following regex:
^[A-Za-z]\w*$
Details
^
- start of string[A-Za-z]
- any ASCII letter\w*
- zero or more letters/digits/_
$
- end of string.To allow an empty string match, wrap the whole pattern with an optional non-capturing group:
^(?:[A-Za-z]\w*)?$
^^^ ^^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With