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;
}
}
{
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>

浙公网安备 33010602011771号