var reg = /^\d{4}$/; var str = "0001" ; reg.test(str); 转载于:https://www.cnblogs.com/libin6505/p/8492139.html