title: PHP: Check that a string doesn't contain any special characters but periods
body: <p>I need to check if a string is valid domain name or host address. This is because I need to block all unfriendly commands from the given string.</p>
  
  <p>One generic solution could be pinging the given address and see if it responses but unfortunately in my case this is not an option.</p>
  
  <p>I think that possible characters are A-Z, a-z, all numbers and the dot '.' so preg_match function could be a way to go. My knowledge of regex is about zero but I managed to find out the following line to check everything else but the dots.</p>
  
  <pre><code>preg_match("/([a-zA-Z0-9])/", $mystring);
  </code></pre>
  
  <p>So could you guys help me out for the right regex syntax to allow the characters mentioned above? Or if you come up with a better solution to block that possible security issue (the string will end up in shell_exec function so it's quite critical) please spit it out. Thanks! :)</p>
  
  <p>EDIT: So possible inputs are for example a typical IP address: 123.123.123.123 or a domain name mydomain.com or corp.mydomain.xx.com. The number of dots is not constant.</p>