开发者

validation for a field to avoid a dot in it in rails

开发者 https://www.devze.com 2023-02-19 17:32 出处:网络
i have a field in my sign up form . I have the reqiurement that my login field should not contain any dot in it

i have a field in my sign up form . I have the reqiurement that my login field should not contain any dot in it

so in my model i wrote like

validates_inclusion_of :login, :in => %w(.), :message => "sho开发者_StackOverflow中文版uld not contain dot!"

Is this correct one ..

The above thing works for me .. but i dont know how is it working ...

As per the documentation 's inclusion should check for the characters inside and if not it should reject rite??

But how come its doing in reverse ??

Please give suggestions..


Maybe you should use something like this:

validates_format_of :login,
                    :with => /^[^\.]*$/,
                    :message => "should not contain dot!"


you can try this

validates :login, :format => { :with => /[^.]*/ }
0

精彩评论

暂无评论...
验证码 换一张
取 消