Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I want to write validations for textboxes in .aspx page using javascript. Everything works fine. But my problem is with regular expression for name. I want to have a regular expression which accepts only alphabets and a space between last name and firstname. I cannot get that. So please suggest me with the solution. Thanks in advance.
Posted

Try:
[a-zA-Z]+\s[a-zA-Z]+

Get a copy of Expresso [^] - it's free, and it examines and generates Regular expressions.
 
Share this answer
 
Comments
Member 8876127 10-May-12 2:48am    
I have tried this too. This did not work.
OriginalGriff 10-May-12 3:02am    
It works for me - how did you try it, and what did it do / not do when you fed it what?
It's a bit more complicated than you think. Look at some of our CP members' real names:
Pete O'Hanlon
Ennis Ray Lynch, Jr.
Wong Shao Voon
Bassam Abdul-Baki
and all the McDonalds and so on.

Having said all that, here's a regex that works for all members of our Rural Fire Service brigade website (which I look after):
^[A-Z]['a-z][a-zA-Z]*\s([a-zA-Z]+\s)?[A-Z]['a-z][-a-zA-Z]*$
Run it through Expresso (see our Free Tools forum for details) if you want to see what it does. It's far from perfect, but it catches most mistakes made by well-meaning people (Australians, anyway :) ).

Cheers,
Peter
 
Share this answer
 
XML
Check this code...

<asp:TextBox ID="txtNumber" runat="server" OnTextChanged="maxchar"></asp:TextBox>

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="only characters allowed" ControlToValidate="txtNumber" ValidationExpression="^[a-z]*$" ></asp:RegularExpressionValidator>

for more detail check the link

http://forums.asp.net/t/1272776.aspx/2/10[^]
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900