dinesh
dinesh

Reputation: 229

RegularExpression for checking string length?

javascript regular expresion to check string length it will rise an error when string length exceeds 250 cheracters

Upvotes: 1

Views: 680

Answers (2)

user557597
user557597

Reputation:

This might work. Match means error.

/.{251}/s

Upvotes: 0

Fabrizio Calderan
Fabrizio Calderan

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

Related Questions