js中的正则
1 正则总结
http://www.blogjava.net/onejavaer/articles/79070.html
2 判断中文、英文、数字 http://hi.baidu.com/stodbx2002/blog/item/95f1e4d4a21e660ea18bb7f1.html
中文:var reg=/^[\u4E00-\u9FA5]+$/; 3 string去掉空格(用到了原型、对象的思想,String.prototype这种方式在高级程序设计中不建议)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>去掉多余空格</title>
</head>
<script type="text/javascript">
function trimstring(strchange)
{
this.str=strchange;
}
trimstring.prototype={
constructor:trimstring,
trim:function() {this.str=this.str.replace(/(^\s+)|(\s+$)/g,"");},
lrim:function() {this.str=this.str.replace(/^\s+/g,"");},
rrim:function() {this.str=this.str.replace(/\s+$/g,"");},
allrim:function() {this.str=this.str.replace(/\s+/g,"");},
getstr:function(){return this.str;}
};
function detrim() //去掉左右空格,其他类似,调用相应函数,略
{
var a =new trimstring(document.getElementById("trim").value);
a.trim();
document.getElementById("trim").value=a.getstr();
}
</script>
<body>
<input id="trim" value=" 两边空格 " /> <input type="button" value="两边空格" onclick="detrim()" />
<input id="ltrim" value=" 左边空格" /> <input type="button" value="左边空格" />
<input id="rtrim" value="右边空格 " /> <input type="button" value="右边空格" />
<input id="alltrim" value=" 所有 空格 " /> <input type="button" value="所有空格" />
</body>
</html> 相关推荐
pythonclass 2020-05-14
玫瑰小妖 2020-04-22
WebVincent 2020-03-28
nercon 2020-03-06
爱好HtmlCssJs 2020-01-23
爱好HtmlCssJs 2020-01-08
html0 2012-01-09
谷歌架构师 2019-06-29
gaohongijj 2017-07-05
zhangpeng 2017-03-08
wangnan0 2016-09-08
勤能补拙孰能生巧 2019-06-28
二毛妮子 2014-09-28
Burgdan 2014-05-21
魄竹 2014-04-30
PioneerFan 2013-05-26
SPARK 2009-05-06
雨中怡然 2012-11-01
努力的zhiyi 2012-06-19