Regular expression for checking the number of characters in a range

I use the ASP Validation control to verify that multi-line content in a text field is between 2 and 40 characters. Any symbol may be provided, including a new line symbol. What will be the expression? What I have below fails.

<asp:RegularExpressionValidator ID="RegularExpressionValidator" 
   runat="server"
   ValidationExpression="^[.]{2,40}$"
   ControlToValidate="CommentsTextBox"
   ErrorMessage="The Comment field must be between 2 and 40 characters" 
   Display="Dynamic">*</asp:RegularExpressionValidator>
+3
source share
2 answers

When you put a point in square brackets, it loses its special meaning and simply corresponds to a literal point. The easiest way to match any character in ASP RegularExpressionValidator:

^[\s\S]{2,40}$

[\s\S] - JavaScript , ( JS DOTALL s-mode, ). .NET, , , .

+3

. :

^(.|\n){2,40}$
+1

Source: https://habr.com/ru/post/1735351/


All Articles