title: Regex to check alphanumeric string in ruby
body: <p>I am trying to validate strings in ruby.
  Any string which contains spaces,under scores or any special char should fail validation.
  The valid string should contain only chars a-zA-Z0-9
  My code looks like.</p>
  
  <pre><code>def validate(string)
      regex ="/[^a-zA-Z0-9]$/
      if(string =~ regex)
          return "true"
      else
          return "false"
  end
  </code></pre>
  
  <p>I am getting error:
  TypeError: type mismatch: String given.</p>
  
  <p>Can anyone please let me know what is the correct way of doing this?</p>