title: How to validate this string not to contain any special characters in Javascript?
body: <p>I have a dynamic string like this which may look like:</p>
  
  <pre><code>"69.43.202.97"                 OR               "ngs.pradhi.com"
  </code></pre>
  
  <p>I want to validate these string contains only numbers, english alphabets and "." . I want to validate this in front end using java script. I thought of using regular expression like this:</p>
  
  <pre><code>function validatePath() {
      var path = document.getElementById('server_path').value;
      path.match([a-z][0-9])  //or something like this
  }
  </code></pre>
  
  <p>If the path is invalid despite of displaying the alert box I just want to show the error below the text field as soon as the user fills the server path. How can I do that?</p>
  
  <p>My full javascript function looks like this:</p>
  
  <pre><code>function validatePath() {
      var path = document.getElementById('server_path').value;
      if (path.search(":") == -1){
          alert("Invalid server path");
      }
      else{
          var host_name = path.split(":")[0]
          if host_name.match("^[a-zA-Z0-9.]*$")) {}
  
      }
  </code></pre>
  
  <p>}</p>