您的位置:首页 > Web前端 > JavaScript

javascript的一些常用正则表达式

2006-07-26 14:42 639 查看
匹配中文字符的正则表达式:              [/u4e00-/u9fa5]

匹配双字节字符(包括汉字在内):           [^/x00-/xff]

匹配空行的正则表达式:                  /n[/s| ]*/r

匹配HTML标记的正则表达式:               /<(.*)>.*<///1>|<(.*) //>/

匹配首尾空格的正则表达式:               (^/s*)|(/s*$)(像vbscript那样的trim函数)

匹配Email地址的正则表达式:              /w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*

匹配网址URL的正则表达式:                http://([/w-]+/.)+[/w-]+(/[/w- ./?%&=]*)?

利用正则表达式限制网页表单里的文本框输入内容:

1.用正则表达式限制只能输入中文:onkeyup="value=value.replace(/[^/u4E00-/u9FA5]/g,'')"
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/u4E00-/u9FA5]/g,''))"

2.用正则表达式限制只能输入全角字符: onkeyup="value=value.replace(/[^/uFF00-/uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/uFF00-/uFFFF]/g,''))"

3.用正则表达式限制只能输入数字:onkeyup="value=value.replace(/[^/d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))"

4.用正则表达式限制只能输入数字和英文:onkeyup="value=value.replace(/[/W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))"  

<script type="text/javascript"><!--
google_ad_client = "pub-0068659036624865";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel ="";
//--></script><script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息