title: How To Use JavaScript Switch Case in Filed Validation
body: <p>I am trying a simple input validation at <a href="http://jsfiddle.net/Behseini/L8cv13tu/" rel="nofollow">This Demo</a> and as you can see I am using some nested if statements (which can be more for applying more validation rules). Now my question is if you can help me to use JavaScript Switch Statement instead of theses if statement
  the reason which I got confused is the <code>(expression)</code> and <code>default:</code> part of the statement which I am totally confused how to use them in my case?</p>
  
  <pre><code>switch(expression) {
      case n:
          code block
          break;
      case n:
          code block
          break;
      default:
          default code block
  }
  </code></pre>
  
  <p>and here is my code:</p>
  
  <pre><code>$(function () {
      $("#pro").on("click", function (e) {
          inputData = $.trim($('input[type="text"]').val());
          if (inputData == ""){
              alert("Field Can not be Empty");
          }
          else if (inputData.length&lt;3){
              alert("Field Can Be Less Than 4");
          }
          else
          {
           alert($('input[type="text"]').val());
          }
          e.preventDefault();
      });
  });
  </code></pre>
  
  <p>Thanks</p>