title: PHP Datetime::format
body: <p>I would like to create a function which validates a date string.</p>
  
  <p>My module displays a date, and in the backend there are some example formats the user can use to display the date on the frontend, and also an advanced date format input where he can specify a date format string like 'H:i:s' or whatever he wants.</p>
  
  <p>If no advanced format option is specified, it uses the default format.</p>
  
  <p>To check the validity of the enterred format in the input, I thought I can do :</p>
  
  <p>$now = new Datetime('now');</p>
  
  <p>if (!$now->format($format)) .... false format</p>
  
  <p>But the format method doesn't return false if $format = x or efkjfkefefje, it just returns the string itself.</p>
  
  <p>I would like it to return false if there is a caracter that differs from the specified caracters here : <a href="http://www.php.net/manual/en/function.date.php" rel="nofollow">http://www.php.net/manual/en/function.date.php</a></p>
  
  <p>But there are so many cases. For example 'H:i:s' would be valid but 'His' Won't be.</p>
  
  <p>I don't want it to parse the ':' or '/', I mean we can consider that 'H/i/s' is valid, because it's an input for advanced users only.</p>
  
  <p>I would like it to return false if a caracter differs from the list here <a href="http://www.php.net/manual/en/function.date.php" rel="nofollow">http://www.php.net/manual/en/function.date.php</a> or if there is no space between caracters : 'His' is not valid whereas the 3 caracters alone are.</p>
  
  <p>I'm not very familiar with regex.</p>