Note that there are some explanatory texts on larger screens.

plurals
  1. POHelp me generate this regex
    text
    copied!<p>I have been trying to use regex but I cant seem to get it to work. I'm trying to use regex with the asp.net <code>RegularExpressionValidator</code>. What I want it to do is to basically disallow leading and trailing spaces only.</p> <p>So,</p> <pre><code>"hello " // would not work. "hello my name is" // would work. </code></pre> <p>But in all my attempts it says bad input no matter what I put in.</p> <p>Here is what I used:</p> <pre><code>^\s[a-z]+\s$ </code></pre> <p>Can someone please provide one that works?</p> <p>And also, what does it mean when someone says the regex returned a match?</p> <p>Edit:</p> <p>I have tried all the solutions in the thread and none of them work for me. Maybe it is something else wrong and not the regex? Heres is the relevant code:</p> <pre><code> &lt;InsertItemTemplate&gt; &lt;asp:TextBox CssClass="tbUpdateSummary" TextMode="MultiLine" Text='&lt;%# Bind("updateSummary") %&gt;' ID="tbUpdateSummaryInsert" runat="server"&gt;&lt;/asp:TextBox&gt; &lt;asp:RequiredFieldValidator ID="valUpdateSummaryInsert1" runat="server" Display="None" ControlToValidate="tbUpdateSummaryInsert" ErrorMessage="Update summary must not be empty."&gt; &lt;/asp:RequiredFieldValidator&gt; &lt;asp:RegularExpressionValidator ValidationExpression="^\s+|\s$" ID="valUpdateSummaryEdit2" runat="server" Display="None" ControlToValidate="tbUpdateSummaryInsert" ErrorMessage="Update summary must not contain leading or trailing spaces."&gt; &lt;/asp:RegularExpressionValidator&gt; &lt;%--Put c# code to validate length (max 200)--%&gt; &lt;asp:CustomValidator&gt;&lt;/asp:CustomValidator&gt; &lt;/InsertItemTemplate&gt; </code></pre> <p>^[^\s].+[^\s]$ &lt;======= This one actually works!! </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload