title: Postgresql - how to disallow use of spaces in some string fields
body: <p>I want to disallow the use of spaces in some text/varchar fields.</p>
  
  <p>Even more, it would be best to have only a set of characters that are allowed to use there, like:</p>
  
  <pre><code>[a-zA-Z0-9_\-]
  </code></pre>
  
  <p>And I want to make it as a rule to all <code>VARCHAR</code> fields that are members of <code>primary key</code> in their tables. </p>
  
  <p>This should be done on the database level and could throw an exception when trying to insert a wrong record or update one with a change of a key field to invalid value.</p>
  
  <p>Can this be done within the database level? Should I use <code>Pl/Perl</code> for that, or is there any simpler method?</p>