Regex I copied into my Rails model won't work?
Brand spanking new to Regex in Rails so please be gentle... I found the following on Regexlib.com to validate no spaces.
^[a-zA-Z]+$
But when I put it into
validates_format_of :first_name, :with => ^[a-zA-Z]+$
I get an error saying unexpected 开发者_Python百科tCARET. What's the problem?
The syntax for a regex in Ruby is /regex/
. So in your case /^[a-zA-Z]+$/
.
精彩评论