这是错误的。例如,这是正确的-ddd,2ddd,2d2ddd,w4hh2ww和2dd,2d2d2d,dd2d,dd2d2d2d2d这是错误的,但它工作不正确,/^[a-zA-Z0-9]+[a-zA-Z]{2}/ or /^[a-zA-Z0-9]+[a-zA-Z]{3}/
您可以尝试/(^[a-zd]*[a-z]{3}[a-zd]*$)|(^d+$)/i
const src = ['2ttt78','q6n','44aaa78','a8','!bbb9','9c','9ddd','2w2www','2d2d2d', '78'],
pattern = /(^[a-zd]*[a-z]{3}[a-zd]*$)|(^d+$)/i
src.forEach(s =>
console.log(`${s} is valid: `, pattern.test(s)))
.as-console-wrapper{min-height:100%;}