正则表达式,不输入超过250个单词 [英] Regular Expression for not entering more than 250 words
问题描述
Hello Friends,
我正在网站上工作,我的要求是我需要限制评论文本框输入不超过250个单词。我在该文本框上应用了multimode属性,因为这个maxlength属性不起作用。所以我使用正则表达式验证器来设置限制。现在我需要一个正则表达式,限制用户输入不超过250个单词。请帮帮我。谢谢。
尝试限制为多个字符(从存储的角度来看更合理): http://stackoverflow.com/questions/6111593/asp-text-box-limit-number-of-characters [ ^ ]
检查:
TextBox:使用ASP.Net RegularExpression验证器进行最小和最大字符长度验证 [ ^ ]
< BLOCKQUOTE>作为总结一个单词的定义是一个或一组空格分隔的字符,那么你可能只想使用字符串拆分函数来计算单词的数量
string s = 你好世界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;
}
在上面的测试中,输出为5个字,忽略额外的空格。
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.
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[^]
Check:
TextBox: Minimum and Maximum Character Length Validation using ASP.Net RegularExpression Validators[^]
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
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.
这篇关于正则表达式,不输入超过250个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!