const reg = /(?!.*\s)(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[^a-zA-Z0-9]).{8,30}/ const passArr = [ "Desktop#sz06", "Desktop#sz0\6", "Desktopsz0\6", "Desktopsz06", "Desktop#sz06 ", "Desktop#s z06", " Desktop#sz06", ] passArr.forEach((item)=>{ console.log(reg.test(item)); })