简体   繁体   中英

Why does my regex work in .NET but not in Javascript?

I am using an asp RegularExpressionValidator to validate if a textarea has html or encoded html. I need the validator to work client side because I have ValidateRequest set to true on the page. My regex is set to match any string that does not have a less than character followed by an alpha character or an ampersand followed by some number of alpha characters ending in a semi-colon.

^((?![<]{1}[a-z]{1}).)*$
^((?![&]{1}[a-z]+;).)*$

Javascript does not have a concept of Single-Line which lets your period match any character including line breaks. You should use the following in place of your comma: [\\s\\S]

^((?![<]{1}[a-z]{1})[\s\S])*$
^((?![&]{1}[a-z]+;)[\s\S])*$

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM