日期:2014-05-17  浏览次数:20981 次

正则表达式,

<asp:TextBox ID="FSiteNameTextBox" ValidationGroup="edit" MaxLength="50" runat="server" 
Text='<%# Bind("FSiteName") %>' />
<asp:RegularExpressionValidator 
ValidationGroup="edit"
ID="RegularExpressionValidator1"  
ControlToValidate="FSiteNameTextBox" 
runat="server" CssClass="error" 
ErrorMessage="网站名长度不能超过50" 
ValidationExpression="\w{1,50}" 
Text="网站名长度不能超过50">
</asp:RegularExpressionValidator>

------解决方案--------------------
汗 错了 

^\w{1,50}$

------解决方案--------------------
ValidationExpression="^\w{1,50}$" 
------解决方案--------------------
 ValidationExpression="[0-9a-zA-Z_\u4e00-\u9fa5]{1,50}"
------解决方案--------------------
^\S{1,50}$
------解决方案--------------------
匹配中文字符的正则表达式: [\u4e00-\u9fa5]
匹配双字节字符(包括汉字在内):[^\x00-\xff]
应用:计算字符串的长度(一个双字节字符长度计2,ASCII字符计1)
String.prototype.len=function(){return this.replace([^\x00-\xff]/g,"aa").length;}

匹配空行的正则表达式:\n[\s
------解决方案--------------------
 ]*\r

匹配HTML标记的正则表达式:/<(.*)>.*<\/\1>
------解决方案--------------------
<(.*) \/>/ 

匹配首尾空格的正则表达式:(^\s*)
------解决方案--------------------
(\s*$)

应用:javascript中没有像vbscript那样的trim函数,我们就可以利用这个表达式来实现,如下:
String.prototype.trim = function()
{
return this.replace(/(^\s*)
------解决方案--------------------
(\s*$)/g, "");
}
------解决方案--------------------
非空的字符需要50个左右
^\S{1,50}$
------解决方案--------------------
\w:匹配任何字类字符,包括下划线。与“[A-Za-z0-9_]”等效。 
\S:匹配任何非空白字符。等价于 [^ \f\n\r\t\v]。