Surya sasidhar
Surya sasidhar

Reputation: 30313

regular expression ^[A-Za-z ]+$

^[A-Za-z ]+$ this expression working but it is not accepting single space i want to accept one space like 'data base'. ^[A-Za-z ]+$ this expression not taking space it taking like 'database' i want 'data base' like this help me. thank u

Upvotes: 0

Views: 2513

Answers (3)

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

should be look like

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="TextBox1"
        ValidationExpression="^[A-Za-z ]+$" runat="server" ErrorMessage="RegularExpressionValidator"></asp:RegularExpressionValidator>
^[A-Za-z ]+$

As if you will see in the expression , there is space after small z, and this would allow space

Upvotes: 1

David Johnstone
David Johnstone

Reputation: 24450

Even if what you had worked as you wanted, it will also match "d a t a b a s e". If you want it to match one space that might (or might not) be in the word, use something like ^[a-zA-Z]+( [a-zA-Z]+)?$

Upvotes: 3

Williagi
Williagi

Reputation: 87

white space is represented by \s in Regex. Therefore you would want ^[a-zA-Z\s]+$

Upvotes: 0

Related Questions