Skip to content
Discussion options

You must be logged in to vote

The regex you are using checks if the string has at least one alphabet. It doesn't restrict other characters from being present.
It produces an error if we type 1122 but not if we type a1122 because the it contains an alphabet.

To check if a string has only alphabets from beginning to end, you can use /^[a-zA-Z]+$/.
This matches the string only if it contains alphabets and nothing else.

Also, there is no need to wrap the regex in double quotes.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mirai-cmd
Comment options

Answer selected by mirai-cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants