如何判断输入的字符串是不否为数字,字母??
下面是我的程序,在关于判断输入的密码是否为数字字母时,虽然输入了数字字母但仍提示"密码只能为数字和字母!"高手帮我看一下怎么会事?还有就是关于判断输入的字符串是否为全空字符串是,我编的程序对不对
<html>
<head>
<title> 无标题文档 </title>
</head>
<body>
<script language= "JavaScript " type= "text/javascript ">
<!--
String.prototype.trim = function()
{
return this.replace(/(^\s*)(\s*$)/g, " ");
}
function check()
{
if(document.form.huiname.value== " ")
{
alert( "用户名不能为空! ");
return false;
}
if((document.form.huiname.value).trim()== " "&&(document.form.huiname.value).length> 0)
{
alert( "用户名不能为全空的字符串! ");
document.form.huiname.focus();
return false;
}
if(document.form.password.value== " ")
{
alert( "密码不能为空! ");
return false;
}
for(var i=0;i <document.form.password.value.length;i++)
{
var onechar=document.form.password.value.charAt(i)
if(onechar < "0 "||onechar> "9 "||onechar < "A "||onechar> "Z "||onechar < "a "||conchar> "z ")
{
alert( "密码只能为数字和字母! ");
document.form.password.focus();
return false;
}
}
if(document.form.address.value== " ")
{
alert( "地址不能为空! ");
return false;
}
if((document.form.address.value).trim()== " "&&(document.form.address.value).length> 0)
{
alert( "地址不能为全空的字符串! ");
document.form.huiname.focus();
return false;
}
}
//-->
</script>
<form name= "form " method= "post " onSubmit= "return check() ">
<table cellpadding= "0 " cellspacing= "0 " width= "650 " border= "1 ">
<tr>
<td height= "36 "> 姓名: </td>
<td> <input type= "text " name= "huiname "> </td>
</tr>
<tr>
<td height= "33 "> 密码: </td>
<td> <input type= "text " name= "password "> </td>
</tr>
<tr>
<td height= "33 "> 地址: </td>
<td> <input type= "text " name= "address "> </td>
</tr>
<tr>
<td height= "35 "> <input name= "Submit " type= "submit " value= "进行注册 "> </td