title: JavaScript White Space Validation not working
body: <p>I have written JSP code and I need to check white space validation, But it is not working can someone tell me the reason. While clicking submit button it must validate for white space and characters.</p>
  
  <p><strong>JSP Code</strong></p>
  
  <pre><code>&lt;%-- 
      Document   : LapsePeriodicFeedBack
      Created on : Dec 7, 2012, 2:50:28 PM
      Author     : Admin
  --%&gt;
  
  &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;%@ page import="java.util.*" %&gt;
  &lt;%@page import="PeriodicFeedBack.PeriodicType"%&gt;
  
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;LapsePeriodicList&lt;/title&gt;
          &lt;script&gt;
              function validateForm(){
  
                  var selectindex=document.forms["lapse"]["periodmenu"].selectedIndex;
                  var whitespace = new RegExp("^\w*$");
                  var x= document.forms["lapse"]["lapsedays"].value;
                  var textlength=document.forms["lapse"]["lapsedays"].length;
                  if(x==""){
                      alert("Days Cant Be Empty");
                      return false;
                  }
                  if(x==whitespace){
                      alert("White Spaces are not Allowed");
                      return false;
                  }
                  if(selectindex==0){
  
                      alert("Please select Days from menu");
                  }
  
  
              }
              if(x=="/\\s"){
                      alert('Sorry, you are not allowed to enter any spaces');
                      x.value=x.value.replace(/\s/g,'');
                      }
  
          &lt;/script&gt;
  
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form  method="post" name="lapse" onsubmit="return validateForm()"&gt;
              &lt;table width="500px" border="1" align="center" style='border-collapse: collapse;font: 13px Arial, Helvetica, sans-serif;' bordercolor='#000000'&gt;
  
                  &lt;tr  style="color:'#ffffff';background-color:#CA1619;background-repeat:repeat-x;font: 13px Arial, Helvetica, sans-serif;"&gt;
                      &lt;td colspan="4" align="center"&gt;
                  &lt;font color="#ffffff" &gt; &lt;b&gt;Periodic Feedback List&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td align="center"&gt;
                      Periodic Feedback Days&lt;/td&gt;
                      &lt;td align="center"&gt;
                          &lt;select id="periodmenu"&gt;
                              &lt;option&gt; Select&lt;/option&gt;
                              &lt;%
          PeriodicType p = new PeriodicType();
          ArrayList periodicList = p.getPeriodicType();
          for (int i = 0; i &lt; periodicList.size(); i++) {%&gt;
                              &lt;option&gt;
  
                                  &lt;% out.println(periodicList.get(i));
          }%&gt;
                              &lt;/option&gt;
                      &lt;/select&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td align="center"&gt;
                      Lapse Days &amp;nbsp;&lt;/td&gt;
                      &lt;td align="center"&gt;
                          &lt;p&gt;
                              &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;
                          &lt;input name="lapsedays" type="text" id="lapsedays" onkeyup="nospaces(this)"/&gt;&lt;/p&gt;
                      &lt;input name="Submit" type="submit" value="Submit" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
              &lt;/table&gt;
          &lt;/form&gt;
          &lt;p&gt;
          &amp;nbsp;&lt;/p&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>