Sometimes, we want to define a regex pattern to match at least 1 number and 1 character in a string with JavaScript.
In this article, we’ll look at how to define a regex pattern to match at least 1 number and 1 character in a string with JavaScript.
How to define a regex pattern to match at least 1 number and 1 character in a string with JavaScript?
To define a regex pattern to match at least 1 number and 1 character in a string with JavaScript.
For instance, we write
const re = /^(?:[0-9]+[a-z]|[a-z]+[0-9])[a-z0-9]*$/i;
to match at least one number with [0-9]+
.
And we match one character with [a-z]
.
i
lets us match in a case insensitive manner.
Conclusion
To define a regex pattern to match at least 1 number and 1 character in a string with JavaScript.