Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
javascript正则表达式检查字符串长度当字符串长度超过250个字符时会出现错误
无需使用昂贵的正则表达式
只需将length属性用于字符串,例如
length
var s = "abcd...xyz"; console.log(s.length)
而且,只是为了回答这个问题,正则表达式将是
if (!(/^.{,250}/).test(s)) { /* error */ }
这可能会奏效。匹配意味着错误。
/.{251}/s