title: Regex letters only validation for javascript prompt
body: <p>I have a page where a prompt window pops up and prompts the user for their first and last name. I'm trying to write validation for the prompt window. hitting cancel or leaving blank is working fine, but what I'm stuck on is ensuring the user enters letters only. Below is what I have.</p>
  
  <pre><code>var alphaExp = /^[0-9a-zA-Z]+$/;
  
  var name=prompt("Enter your first and last name please.","");
  if (name==null || name=="")
    {
    alert("First and last name must be filled out!");
    location.reload(true);
    }
  else if (name==alphaExp)
    {
    alert("Name must contain letters only!")
    location.reload(true);
    }
  </code></pre>
  
  <p>If I hit cancel or leave blank, I'm alerted that the field must be filled out and the page refreshes, but if I enter a number or special character it accepts it and takes me to the page, which it shouldn't.</p>
  
  <p>I tried changing </p>
  
  <pre><code>else if (name==alphaExp)
  </code></pre>
  
  <p>to</p>
  
  <pre><code>else if (name!=alphaExp)
  </code></pre>
  
  <p>but that seemed to give the opposite effect of what I wanted and accepted nothing.</p>
  
  <p>What am I missing here?</p>
  
  <p>Also, what if statement would I have to write to ensure the user enters at least two names? i.e. must be 1 letter + a space + 1 letter. suggestions?</p>