asp.net - RegularExpressionValidator slow on multiline textbox (textarea) -
i have multiline textbox (textarea) want verify has particular string in it. trying:
<asp:regularexpressionvalidator runat="server" controltovalidate="txttemplate" validationexpression="^(.\s*)*content(.\s*)*$" text="content" errormessage="must contain: content" /> using ^(.\s*)*$ seems pass textarea. tried sandwich criteria between 2 of these. seems lock both ie , chrome.
this should simple, think i'm making tougher needs be.
if validation being done on server (that's runat="server" means, isn't it?), simplest solution use regex:
(?s)^.*content.*$ (?s) turns on singleline mode, allows . metacharacter match characters including linefeeds. if want run on client well, use this:
^[\s\s]*content[\s\s]*$ that's because javascript has no equivalent singleline mode (also known dot_all, dotall, dot-matches-all, single-line, or /s mode). doesn't recognize inline modifiers (?s) , (?i), either.
watch out constructs (.\s*)*, expression quantifiers (*, +, etc.) enclosed in group controlled quantifier. if regex fails achieve match right away, goes , tries match different paths (i.e., using different parts of regex match different parts of string), can expensive, performance-wise. regex bad because . , \s can match many of same characters, dramatically increases number of paths has explore before giving up.
the phenomenon commonly known catastrophic backtracking, , manifests in cases there's no possibility of match. expect validator work fine when sequence content present.
by way, if want match on complete word content, should add word boundaries, so:
(?s)^.*\bcontent\b.*$ that prevent false positives on words malcontent , contentious. \b works differently in different regex flavors. in .net it's unicode-aware unless specify ecmascript mode. in javascript it's supposed recognize ascii letters , digits word characters; in browsers does, don't take granted.
Comments
Post a Comment