Categories
JavaScript Answers

How to do alphanumeric check in JavaScript?

Spread the love

Sometimes, we want to do alphanumeric check in JavaScript.

In this article, we’ll look at how to do alphanumeric check in JavaScript.

How to do way to alphanumeric check in JavaScript?

To do alphanumeric check in JavaScript, we can use a regex.

For instance, we write

const isAlphanumeric = /^[a-z0-9]+$/i.test("abc");

to call ^[a-z0-9]+$/i.test with the string that we want to check if it’s alphanumeric or not.

We use ^[a-z0-9]+$ to check if the whole string only has letters and digits.

And we use i to check that in a case insensitive manner.

Conclusion

To do alphanumeric check in JavaScript, we can 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 *