如何判断输入的字符串是否为全空的字符串??
如何判断输入的字符串是否为全空的字符串??
例如在一个表单中
<form name= "form " method= "post " onsubmit= "return check() ">
<table>
<tr> <td> <input type= "text " name= "huiname "> </td> </tr>
</table>
</form>
如何用如下这种方式判断输入的字符串是全空的字符串?高手帮我,万分感激!!
<script>
function check()
{
if(document.form.huiname.value== ' ')
}
</scritp>
------解决方案-------------------- <script>
String.prototype.trim = function()
{
// 用正则表达式将前后空格,用空字符串替代。
return this.replace(/(^\s*)(\s*$)/g, " ");
}
function check()
{
if((document.form.huiname.value).trim()== " ")
{
}
}
</scritp>
------解决方案--------------------上面是判断是不是全空的字符串
下面是判断huiname不能为空
<script language= "JavaScript " type= "text/javascript ">
<!--
String.prototype.trim = function()
{
return this.replace(/(^\s*)(\s*$)/g, " ");
}
function check()
{
if((document.form.huiname.value).trim()== " ")
{
alert( "huiname不能为空 ");
document.form.huiname.focus();
return false;
}
}
//-->
</script>
</head>
<body>
<form name= "form " method= "post " onsubmit= "return check(); ">
<table>
<tr> <td> <input type= "text " name= "huiname "> </td> </tr>
<tr> <td> <input type= "submit " value= "submit "> </td> </tr>
</table>
</form>