z333 sb666 z h333 返回false
z555 sb888 x666 返回true
z555 sb888()()x666 返回true(两个空格)
匹配字符串必须是字母+数字
z333 sb666 z h333 返回false
z555 sb888 x666 返回true
z555 sb888()()x666 返回true(两个空格)
匹配字符串必须是字母+数字
将字符串按照空格进行拆分,对每一段进行校验即可,只要其中一个不满足,那么整段字符串就不满足要求
function hasLetterAndNum(str) {
return str.split(/\s+/).every(item => /^(?=.*?[0-9])(?=.*?[a-z])[0-9a-z]+$/.test(item))
}
测试:
hasLetterAndNum('qwerty') // false
hasLetterAndNum('123456') // false
hasLetterAndNum('qwe123') // true
hasLetterAndNum('qwe123 qwe abc46') // false
hasLetterAndNum('qwe123 5566 abc46') // false
hasLetterAndNum('qwe123 5566c abc46') // true
hasLetterAndNum('qwe123 5566c abc46') // true
13 回答12.9k 阅读
7 回答2.1k 阅读
3 回答1.3k 阅读✓ 已解决
2 回答1.3k 阅读✓ 已解决
6 回答1.2k 阅读✓ 已解决
6 回答1.1k 阅读
3 回答1.3k 阅读✓ 已解决