<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script>
//去除头尾空格
String.prototype.trim = function(){
var regs = /^\s+(.*?)\s+$/;
return this.replace(regs,"$1");
};
var sTest =" This is a ";
alert("["+sTest+"]");
alert("["+sTest.trim()+"]");
//替换用户输入的限制的词汇
var regWords = /badword|shit/gi;
var sInput = "This is your life using badword3ss and shit .";
var filterWord = sInput.replace(regWords,"*****");
alert(filterWord);
//去除用户输入的HTML标签
String.prototype.scriptHTML = function(){
var reTag = /<(?:.|\s)*?>/g;
return this.replace(reTag,"");
};
var sTest = "<html><title>xxxx</title></html>";
alert(sTest.scriptHTML());
</script>
<BODY>
</BODY>
</HTML>
posted on 2008-05-20 22:38
bcterry 阅读(101)
评论(0) 编辑 收藏