js 判断/去除空格

去除所有空格:
str = str.replace(/\s+/g,"");
去除两头空格:
str = str.replace(/^\s+|\s+$/g,"");

====================

function abc()
{    
  
var s = document.form1.TxtPrjID.value;
  
if(s.indexOf(" ")!= -1 || s.indexOf(" ")!= -1|| s.indexOf(" ")!= -1||s.indexOf(" ")!= -1)
  {
    alert(
"Can not contain space charator,Please input it again!");
        
    document.getElementById(
'TxtPrjID').focus(); 
    document.getElementById(
'TxtPrjID').value = s.Trim();//s.replace(/\s+/g,"");
    return false
  }
}

==============

<asp:TextBox ID="TxtPrjID" runat="server" onblur="return abc();" MaxLength="20" CssClass="bk"></asp:TextBox>

 

posted @ 2008-10-16 14:35  shuang  阅读(680)  评论(0)    收藏  举报