Spread the love
Sometimes, we want to match only English letters with JavaScript regex.
In this article, we’ll look at how to match only English letters with JavaScript regex.
How to match only English letters with JavaScript regex?
To match only English letters with JavaScript regex, we use a regex that matches upper and lower letters only.
For instance, we write
const res = /^[a-zA-Z]+$/.test("abcd");
console.log(res);
to match upper and lower case letters with a-z
and A-Z
.
^
indicates the start of the string and $
indicates the end.
We call test
to check if 'abcd'
matches the pattern.
Conclusion
To match only English letters with JavaScript regex, we use a regex that matches upper and lower letters only.