tags:

views:

147

answers:

3

^[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

A: 

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

Williagi
No. \s is an an character class which matches [\f\n\r\t\v\x85\p{Z}], so it can take other chars than space.
Rubens Farias
Williagai said "white space"
Artelius
yes, but the poster wants a single space
Dave Arkell
+3  A: 

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]+)?$

David Johnstone
ya it is working mr.david johnstone
Surya sasidhar
+1  A: 

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

Muhammad Akhtar
Its confirmed as I have checked in my machine
Muhammad Akhtar
thank u dude i not observer clearly thank u muhammad
Surya sasidhar
Isn't this the same regex as in the question?
David Johnstone
@David, yes man :)
Muhammad Akhtar
If you have multiple consecutive spaces, your solution will catch that as well, but that is perhaps ok with you.
UlfR