Categories
JavaScript Answers

How to check if string contains Latin characters only with JavaScript?

Spread the love

Sometimes, we want to check if string contains Latin characters only with JavaScript.

In this article, we’ll look at how to check if string contains Latin characters only with JavaScript.

How to check if string contains Latin characters only with JavaScript?

To check if string contains Latin characters only with JavaScript, we use a regex.

For instance, we write

if (str.match(/[a-z]/i)) {
  // ...
}

to check if string str has only a to z in a case insensitive manner.

We call match to find any matches with this pattern.

Conclusion

To check if string contains Latin characters only with JavaScript, we use a regex.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *