原代码是:
function getlengthB(str)
{ return str.replace(/[" "^\x00-\xff\]/g,"").length;
}
function Checkdata()
{
document.getElementById("titlestr").innerHTML="";
document.getElementById("constr").innerHTML="";
ischeck=true
CheckUbbUse('UserName',1,document.getElementById('Body').value)//定员帖检查
if (getlengthB(document.Dvform.topic.value)<3 && ispostnew==1)
{
document.getElementById("titlestr").innerHTML=" <font color=\"#FF0000\">←您忘记填写标题</font>"
document.Dvform.topic.focus();
ischeck=false
}
想在getlengthB函数中增加去掉空格的命令
function getlengthB(str)
{ return str.replace(/[" "^\x00-\xff\]/g,"").length;
}
function Checkdata()
{
document.getElementById("titlestr").innerHTML="";
document.getElementById("constr").innerHTML="";
ischeck=true
CheckUbbUse('UserName',1,document.getElementById('Body').value)//定员帖检查
if (getlengthB(document.Dvform.topic.value)<3 && ispostnew==1)
{
document.getElementById("titlestr").innerHTML=" <font color=\"#FF0000\">←您忘记填写标题</font>"
document.Dvform.topic.focus();
ischeck=false
}
想在getlengthB函数中增加去掉空格的命令
{ return str.replace(/\s/g,"").replace(/[" "^\x00-\xff\]/g,"").length;
}
试试~~~~~~~~~~·
{ return str.replace(/[^\x00-\xff]/g,"").length;
}
这个函数加入去除空格的功能
※以下是引用楼主 linhongsha() 在2007-7-13 10:54:53 的发言:
──────────────────────────────────────────
function getlengthB(str)
{ return str.replace(/[^\x00-\xff]/g,"").length;
}
这个函数加入去除空格的功能
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
function getlengthB(str)
{
return str.replace(/[\u0100-\uffff ]/g,"").length;
}
{
return str.replace(/[\u0100-\uffff ]+/g,"").length;
}这样写效率会高一点点
function getlengthB(str)
{
return str.replace(/[\u0100-\uffff ]+/g,"").length;
}
已经达到你的要求了,注意\u0100-\uffff后面有一个空格的。