Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to allow alphabets, white spaces and apostrophe in validation. I am using following expression. what will be the change I supposed to do .?

What I have tried:

<asp:RegularExpressionValidator ID= "REVOcc"  runat="server" ControlToValidate="txtOccasion" ValidationExpression="^[a-zA-Z]+(\s[a-zA-Z]+)?$"
                      ErrorMessage="No numbers and special characters are allowed" ForeColor="Red" ValidationGroup="SaveOccasion"></asp:RegularExpressionValidator>
Posted
Updated 7-Aug-17 2:41am
v2
Comments
Kornfeld Eliyahu Peter 7-Aug-17 6:54am    
For nice visualization - it helps to understand what you got there...
https://regexper.com/#%5E%5Ba-zA-Z%5D%2B(%5Cs%5Ba-zA-Z%5D%2B)%3F%24

Your current regex is:
- Begins with one or more ASCII alpha characters
- Optionally followed by a single white space and one or more ASCII alpha characters

For your request I would just add all allowed characters to the range:
"^[a-zA-Z\s']+$"
 
Share this answer
 
Comments
Simon Ferry 7-Aug-17 6:51am    
Ohh, thanks a lot)
Jochen Arndt 7-Aug-17 6:55am    
You are welcome.

But you probably replied in the wrong thread. I guess you wanted to reply at your Excel reading question.
Quote:
I want to allow alphabets, white spaces and apostrophe in validation. I am using following expression. what will be the change I supposed to do .?

How can you write ^[a-zA-Z]+(\s[a-zA-Z]+)?$ and be unable to do such basic changes ?
You already have a space in your expression, but you are unable to put another one ?
What did you try and what are problems you got ?
Describe what you want to match.

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
 
Share this answer
 
/^([a-zA-Z ']*)$/
Try this, hope it will fit to your needs.
 
Share this answer
 

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