z333sb666zh333返回falsez555sb888x666返回truez555sb888()()x666返回true(两个空格)匹配字符串必须是字母+数字
2 回答
守着星空守着你
TA贡献1799条经验 获得超8个赞
将字符串按照空格进行拆分,对每一段进行校验即可,只要其中一个不满足,那么整段字符串就不满足要求functionhasLetterAndNum(str){returnstr.split(/\s+/).every(item=>/^(?=.*?[0-9])(?=.*?[a-z])[0-9a-z]+$/.test(item))}测试:hasLetterAndNum('qwerty')//falsehasLetterAndNum('123456')//falsehasLetterAndNum('qwe123')//truehasLetterAndNum('qwe123qweabc46')//falsehasLetterAndNum('qwe1235566abc46')//falsehasLetterAndNum('qwe1235566cabc46')//truehasLetterAndNum('qwe1235566cabc46')//true
添加回答
举报
0/150
提交
取消