Reputation: 229
javascript regular expresion to check string length it will rise an error when string length exceeds 250 cheracters
Upvotes: 1
Views: 680
Reputation: 123377
there's no need to use an expensive regular expression
just use length
property for strings, e.g.
var s = "abcd...xyz";
console.log(s.length)
and, just to answer the question, the regular expression would be
if (!(/^.{,250}/).test(s)) { /* error */ }
Upvotes: 2