Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Ruby on Rails 可以使用方法验证用户输入validates_length_of。此方法如何处理多字节字符?
validates_length_of
例子
validates_length_of :title, :within => 0..10
"abcde"将通过验证,"12345678901"不会。怎么样"一二三四五六"?它会通过验证吗?
"abcde"
"12345678901"
"一二三四五六"
如果您想计算字符数,它应该正确处理它,它将它作为字符串处理,而不是作为字节处理。
更多信息在这里
http://railspikes.com/2009/7/20/validates_length_of-gotcha