JS 判断录入的是否是空格

<html>
  <head>    
    <title>My JSP 'index.jsp' starting page</title>
 <script type="text/javascript">
  function test()
  {    
   var city=regForm.city.value;
   if(city.indexOf(' ')!=-1){
     alert('内容不能有空格');
     regForm.city.focus();  
     return false;
    }  
  }
 </script>

  </head>
  
  <body>

<form name="regForm" action="index.jsp" method="post">
 <input id="city" name="city" type="text"/>
 <input type="submit" value="测试" onclick="return test();"/>
</form> 
  </body>
 

你可能感兴趣的:(JavaScript,html,jsp)