<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>我爱正则表达式 &#187; asp</title>
	<atom:link href="http://iregex.org/blog/tag/asp/feed" rel="self" type="application/rss+xml" />
	<link>http://iregex.org</link>
	<description>原创、翻译、转载关于正则表达式的文章</description>
	<lastBuildDate>Tue, 31 Aug 2010 04:35:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/><atom:link rel="hub" href="http://www.feedsky.com/api/RPC2"/><atom:link rel="hub" href="http://blogsearch.google.com/ping/RPC2"/><atom:link rel="hub" href="http://blog.yodao.com/ping/RPC2"/><atom:link rel="hub" href="http://www.feedsky.com/api/RPC2"/><atom:link rel="hub" href="http://www.xianguo.com/xmlrpc/ping.php"/><atom:link rel="hub" href="http://www.zhuaxia.com/rpc/server.php"/><atom:link rel="hub" href="http://rpc.technorati.com/rpc/ping"/><atom:link rel="hub" href="http://rpc.pingomatic.com/"/>	
<!-- Start Of Script Generated By WP-PostViews Plus -->
<script type='text/javascript' src='http://iregex.org/wp-includes/js/jquery/jquery.js?ver=1.4.2'></script>
<script type="text/javascript">
/* <![CDATA[ */
/* ]]> */
</script>
<!-- End Of Script Generated By WP-PostViews Plus -->
	<item>
		<title>匹配用户名的asp正则表达式(包括中文)</title>
		<link>http://iregex.org/blog/regular-expressions-to-match-chinese-username-in-asp.html</link>
		<comments>http://iregex.org/blog/regular-expressions-to-match-chinese-username-in-asp.html#comments</comments>
		<pubDate>Sun, 13 Jul 2008 14:01:17 +0000</pubDate>
		<dc:creator>rex</dc:creator>
				<category><![CDATA[问答]]></category>
		<category><![CDATA[asp]]></category>
		<category><![CDATA[chinese]]></category>

		<guid isPermaLink="false">http://iregex.org/?p=18</guid>
		<description><![CDATA[有人在正则表达式中文站贴出这样一道问题： 求ASP 用户名 表达式 用户名长度在2-20字符之间，由中文/大小写字母/数字/中划线-/下线线_组成。 这个问题不算难，只要下边一行核心代码就能搞... ]]></description>
			<content:encoded><![CDATA[<p>有人在<a href="http://www.regex.net.cn" target="_blank">正则表达式中文站</a>贴出<a href="http://www.regex.net.cn/redirect.php?tid=30&amp;goto=lastpost#lastpost" target="_blank">这样</a>一道问题：</p>
<blockquote style="border-left:2px solid #DDDDDD; margin:15px 30px 0 10px; padding-left:20px;">
<h3 style="color: #127ADB; font-size:14px; padding-bottom:3px; padding-top:3px; margin:1.5em 0 1em;">求ASP 用户名 表达式</h3>
<p>用户名长度在2-20字符之间，由中文/大小写字母/数字/中划线-/下线线_组成。</p></blockquote>
<p>这个问题不算难，只要下边一行核心代码就能搞定：</p>
<div class="codecolorer-container perl mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff0000;">&quot;^[-_a-zA-Z0-9<span style="color: #000099; font-weight: bold;">\u</span>4e00-<span style="color: #000099; font-weight: bold;">\u</span>9fa5]{2,20}$&quot;</span></div></td></tr></tbody></table></div>
<p>关键是没有使用过ASP语言。按<span style="color: #6666cc;"><a href="http://www.webase.net.cn/html/Program/Asp/200711/29.html" target="_blank">此页</a></span>的提示，设置了ASP环境。查询了一些在线的入门级ASP教程之后，解答如下：<span id="more-19"></span></p>
<div class="codecolorer-container asp mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="asp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-weight: bold;">&lt;</span>form action<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;verify.asp&quot;</span> method<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;post&quot;</span><span style="color: #006600; font-weight: bold;">&gt;</span><br />
姓名：<br />
<span style="color: #006600; font-weight: bold;">&lt;</span>input name<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;name&quot;</span> type<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;text&quot;</span> <span style="color: #006600; font-weight: bold;">/&gt;</span><br />
<br />
<span style="color: #006600; font-weight: bold;">&lt;</span>input name<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;Submit&quot;</span> type<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;submit&quot;</span> value<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;提交&quot;</span> <span style="color: #006600; font-weight: bold;">/&gt;</span><br />
<span style="color: #006600; font-weight: bold;">&lt;</span>input name<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;Submit2&quot;</span> type<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;reset&quot;</span> value<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;重置&quot;</span> <span style="color: #006600; font-weight: bold;">/&gt;</span><br />
<span style="color: #006600; font-weight: bold;">&lt;/</span>form<span style="color: #006600; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>它调用以下verify.asp文件：</p>
<div class="codecolorer-container asp mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="asp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-weight: bold;">&amp;</span>lt<span style="color: #006600; font-weight: bold;">;%</span><br />
<span style="color: #0000ff; font-weight: bold;">Function</span> RegExpTest<span style="color: #006600; font-weight:bold;">&#40;</span>patrn, strng<span style="color: #006600; font-weight:bold;">&#41;</span><br />
<span style="color: #990099; font-weight: bold;">Dim</span> regEx, retVal <span style="color: #008000;">' 建立变量。</span><br />
<span style="color: #990099; font-weight: bold;">Set</span> regEx <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #0000ff; font-weight: bold;">New</span> RegExp <span style="color: #008000;">' 建立正则表达式。</span><br />
regEx.<span style="color: #9900cc;">Pattern</span> <span style="color: #006600; font-weight: bold;">=</span> patrn <span style="color: #008000;">' 设置模式。</span><br />
regEx.<span style="color: #9900cc;">IgnoreCase</span> <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #0000ff; font-weight: bold;">False</span> <span style="color: #008000;">' 设置是否区分大小写。</span><br />
retVal <span style="color: #006600; font-weight: bold;">=</span> regEx.<span style="color: #9900cc;">Test</span><span style="color: #006600; font-weight:bold;">&#40;</span>strng<span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #008000;">' 执行搜索测试。</span><br />
<span style="color: #990099; font-weight: bold;">If</span> retVal <span style="color: #990099; font-weight: bold;">Then</span><br />
RegExpTest <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;合法用户名。&quot;</span><br />
<span style="color: #990099; font-weight: bold;">Else</span><br />
RegExpTest <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;非法用户名。&quot;</span><br />
<span style="color: #990099; font-weight: bold;">End</span> <span style="color: #990099; font-weight: bold;">If</span><br />
<span style="color: #990099; font-weight: bold;">End</span> <span style="color: #0000ff; font-weight: bold;">Function</span><br />
<br />
name<span style="color: #006600; font-weight: bold;">=</span><span style="color: #990099; font-weight: bold;">request</span>.<span style="color: #330066;">form</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;name&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span><br />
psw<span style="color: #006600; font-weight: bold;">=</span><span style="color: #990099; font-weight: bold;">request</span>.<span style="color: #330066;">form</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;psw&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span><br />
sex<span style="color: #006600; font-weight: bold;">=</span><span style="color: #990099; font-weight: bold;">request</span>.<span style="color: #330066;">form</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;sex&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span><br />
city<span style="color: #006600; font-weight: bold;">=</span><span style="color: #990099; font-weight: bold;">request</span>.<span style="color: #330066;">form</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;city&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span><br />
<span style="color: #990099; font-weight: bold;">Response</span>.<span style="color: #330066;">write</span> RegExpTest<span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;^[-_a-zA-Z0-9\u4e00-\u9fa5]{2,20}$&quot;</span>, name<span style="color: #006600; font-weight:bold;">&#41;</span><br />
<span style="color: #006600; font-weight: bold;">%&amp;</span>gt<span style="color: #006600; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>运行界面见附图。<img style="max-width: 800px;" src="http://i3.6.cn/cvbnm/83/1a/5c/bc56d8b70e9fcc5f9565b47cc651def5.jpg" alt="" /></p>
<p>另外，还有一些<a href="http://iregex.org">正则表达式</a>可供参考：</p>
<p>匹配中文字符的<a href="http://iregex.org">正则表达式</a>：</p>
<div class="codecolorer-container asp mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="asp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-weight:bold;">&#91;</span>\u4e00-\u9fa5<span style="color: #006600; font-weight:bold;">&#93;</span></div></td></tr></tbody></table></div>
<p>匹配双字节字符(包括汉字在内)<a href="http://iregex.org">正则表达式</a>：</p>
<div class="codecolorer-container asp mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="asp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-weight:bold;">&#91;</span>^\x00-\xff<span style="color: #006600; font-weight:bold;">&#93;</span></div></td></tr></tbody></table></div>
<p>匹配空行的<a href="http://iregex.org">正则表达式</a>：</p>
<div class="codecolorer-container asp mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="asp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">\n<span style="color: #006600; font-weight:bold;">&#91;</span>\s<span style="color: #006600; font-weight: bold;">|</span> &nbsp; <span style="color: #006600; font-weight:bold;">&#93;</span><span style="color: #006600; font-weight: bold;">*</span>\r</div></td></tr></tbody></table></div>
<p>匹配HTML标记的<a href="http://iregex.org">正则表达式</a>：</p>
<div class="codecolorer-container asp mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="asp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-weight: bold;">/</span> <span style="color: #006600; font-weight: bold;">&amp;</span>lt<span style="color: #006600; font-weight: bold;">;</span><span style="color: #006600; font-weight:bold;">&#40;</span>.<span style="color: #006600; font-weight: bold;">*</span><span style="color: #006600; font-weight:bold;">&#41;</span><span style="color: #006600; font-weight: bold;">&amp;</span>gt<span style="color: #006600; font-weight: bold;">;</span> .<span style="color: #006600; font-weight: bold;">*</span> <span style="color: #006600; font-weight: bold;">&amp;</span>lt<span style="color: #006600; font-weight: bold;">;</span>\<span style="color: #006600; font-weight: bold;">/</span>\<span style="color: #800000;">1</span><span style="color: #006600; font-weight: bold;">&amp;</span>gt<span style="color: #006600; font-weight: bold;">;</span> <span style="color: #006600; font-weight: bold;">|</span> <span style="color: #006600; font-weight: bold;">&amp;</span>lt<span style="color: #006600; font-weight: bold;">;</span><span style="color: #006600; font-weight:bold;">&#40;</span>.<span style="color: #006600; font-weight: bold;">*</span><span style="color: #006600; font-weight:bold;">&#41;</span> &nbsp; \<span style="color: #006600; font-weight: bold;">/&amp;</span>gt<span style="color: #006600; font-weight: bold;">;</span> <span style="color: #006600; font-weight: bold;">/</span></div></td></tr></tbody></table></div>
<p>匹配首尾空格的<a href="http://iregex.org">正则表达式</a>：</p>
<div class="codecolorer-container asp mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="asp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-weight:bold;">&#40;</span>^\s<span style="color: #006600; font-weight: bold;">*</span><span style="color: #006600; font-weight:bold;">&#41;</span><span style="color: #006600; font-weight: bold;">|</span><span style="color: #006600; font-weight:bold;">&#40;</span>\s<span style="color: #006600; font-weight: bold;">*</span>$<span style="color: #006600; font-weight:bold;">&#41;</span></div></td></tr></tbody></table></div>
<p>用<a href="http://iregex.org">正则表达式</a>限制只能输入中文：</p>
<div class="codecolorer-container asp mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="asp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">onkeyup<span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;value=value.replace(/[^\u4E00-\u9FA5]/g, ' ') &quot;</span> &nbsp; onbeforepaste<span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;clipboardData.setData( 'text ',clipboardData.getData( 'text ').replace(/[^\u4E00-\u9FA5]/g, ' ')) &quot;</span></div></td></tr></tbody></table></div>
<p>用<a href="http://iregex.org">正则表达式</a>限制只能输入全角字符：</p>
<div class="codecolorer-container asp mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="asp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">onkeyup<span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;value=value.replace(/[^\uFF00-\uFFFF]/g, ' ') &quot;</span> &nbsp; onbeforepaste<span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;clipboardData.setData( 'text ',clipboardData.getData( 'text ').replace(/[^\uFF00-\uFFFF]/g, ' ')) &quot;</span></div></td></tr></tbody></table></div>
<p>用<a href="http://iregex.org">正则表达式</a>限制只能输入数字：</p>
<div class="codecolorer-container asp mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="asp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">onkeyup<span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;value=value.replace(/[^\d]/g, ' ') &nbsp; &quot;</span>onbeforepaste<span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;clipboardData.setData( 'text ',clipboardData.getData( 'text ').replace(/[^\d]/g, ' ')) &quot;</span></div></td></tr></tbody></table></div>
<p>用<a href="http://iregex.org">正则表达式</a>限制只能输入数字和英文：</p>
<div class="codecolorer-container asp mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="asp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">onkeyup<span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;value=value.replace(/[\W]/g, ' ') &nbsp; &quot;</span>onbeforepaste<span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;clipboardData.setData( 'text ',clipboardData.getData( 'text ').replace(/[^\d]/g, ' ')) &quot;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://iregex.org/blog/regular-expressions-to-match-chinese-username-in-asp.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
