-
Basically I wanted to use regex patterns to validate input fields. Specifically print the regex error message. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The regex you are using checks if the string has at least one alphabet. It doesn't restrict other characters from being present. To check if a string has only alphabets from beginning to end, you can use Also, there is no need to wrap the regex in double quotes. |
Beta Was this translation helpful? Give feedback.
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 typea1122
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.