Hello Mike,
> Try "^[a-z]+$". That will also take care of requiring some text to be
> entered, so if you're OK with having one error message taking care of
> "you must enter stuff" and also "you must enter lowercase letters
> only", IE "You must enter lowercase English letters", you can delete
> your RequiredFieldValidator.
That isn't exactly true. The regexValidator by default does not trigger when
the input is empty. This is done because the error message for a required
field is different from an incorrect input.
> The character group square brackets mean to match one character from
> that group, so your current Regular Expression means the user must
> enter one lowercase letter, possibly among other things. The +
> modifier means it must match any of those characters at least once,
> and you could also use the * modifier to match any of those characters
> any number of times (zero is OK). Putting ^ at the beginning means it
> must match that starting with the beginning, and ending with $ means
> it must match that at the end, so together they mean the entire string
> must match it.
>
> -Michael Placentra II
>
> On Oct 3, 12:57 pm, David <david.mccollo...@gmail.com> wrote:
>
>> I'm having trouble getting the regular expression validator to work
>> with a text box.
>>
>> In this simple example I only want lower case letters to be allowed.
>> So I tried the following and it doesn't work, would somebody be so
>> kind as to tell me why.
>>
>> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
>> <asp:RequiredFieldValidator
>> ID="RequiredFieldValidator1"
>> runat="server"
>> ErrorMessage="RequiredFieldValidator"
>> ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
>> <asp:RegularExpressionValidator
>> ID="RegularExpressionValidator1"
>> runat="server"
>> ErrorMessage="RegularExpressionValidator"
>> ControlToValidate="TextBox1"
>> ValidationExpression="[a-z]"></asp:RegularExpressionValidator>
>> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
>> <asp:Button ID="Button1" runat="server" Text="Button"
>> OnClick="Button1_Click" />
>> protected void Button1_Click(object sender, EventArgs e)
>> {
>> if (Page.IsValid)
>> {
>> Response.Write("Page is valid");
>> }
>> else
>> {
>> Response.Write("Page is not valid");
>> }
>> }
--
Jesse Houwing
jesse.houwing at sogeti.nl
|