So you want to check two conditions. Although you can use one complex regular expression, it is better to use two of them:
if (/\d/.test(string) && /[a-zA-Z]/.test(string)) {
This makes your program more readable and may even improve slightly (but not sure about that).
source
share