Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Hello Friends,

I am working on a website and my requirement is that i need to restrict "Comment Textbox" for entering not more than 250 Words. I applied multimode property on that textbox due to this maxlength property is not working. So i used Regular expression validator to put the restriction. Now i need a regular expression that limits the user to enter not more than 250 words. Please help me in this one. Thank you.
Posted
Updated 4-Jul-14 21:30pm
v4
Comments
Bernhard Hiller 8-Jul-14 2:26am    
OhBewareIMightBeAbleToCircumventThatWithoutProblems ButYouMayBeRightItCouldBeAWTFRequirementByARequirementsEngineerWhoDoesNotUnderstandTheIssueBehindTheRestriction

Try limiting to a number of characters instead (which is more reasonable from a storage standpoint): http://stackoverflow.com/questions/6111593/asp-text-box-limit-number-of-characters[^]
 
Share this answer
 
Comments
Maciej Los 7-Jul-14 16:56pm    
+5!
 
Share this answer
 
Comments
Maciej Los 7-Jul-14 16:56pm    
+5!
ridoy 8-Jul-14 13:58pm    
Thank you, Maciej. :)
Assuming that the definition of a word is one or a group of character(s) that is space delimited, then you may want to just count the number of words using the string split function

C#
    string s = "hello world  1   2  3  ";
    System.Diagnostics.Debug.WriteLine(GetNumWord(s)+ " words");

int GetNumWord(string s)
{
    var words=s.Split(new char[] {' '},StringSplitOptions.RemoveEmptyEntries);
    return words.Length;

}


In the above test, the output is 5 words, extra spaces are ignored.
 
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