Hi How I can check on models controller if item has space on it and if yes then return error ? ie. on form you have textbox myitem and if users fills in there like: xxx yyyy (ie. space on middle or end of value) then this should return an error saying that no space is allowed on that field ? Thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Feb-10 18:13 UTC
Re: check if space exists on the value and if yes prompt for error
On 10 Feb 2008, at 16:52, KTU wrote:> > Hi > > How I can check on models controller if item has space on it and if > yes then return error ? > > ie. on form you have textbox myitem and if users fills in there like: > xxx yyyy (ie. space on middle or end of value) > then this should return an error saying that no space is allowed on > that field ? > >validates_format_of ? Fred> Thanks > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
KTU
2008-Feb-10 19:28 UTC
Re: check if space exists on the value and if yes prompt for error
Jep I got it validates_format_of :intname, :with => /^[a-zA-Z0-9]*?$/, :message => ''Internal name can only contain letters & numbers and nospaces'' On Feb 10, 8:13 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 10 Feb 2008, at 16:52, KTU wrote: > > > > > Hi > > > How I can check on models controller if item has space on it and if > > yes then return error ? > > > ie. on form you have textbox myitem and if users fills in there like: > > xxx yyyy (ie. space on middle or end of value) > > then this should return an error saying that no space is allowed on > > that field ? > > validates_format_of ? > > Fred > > > Thanks--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
AndyV
2008-Feb-11 17:53 UTC
Re: check if space exists on the value and if yes prompt for error
Is the problem that the regex validation is working correctly but you do not know that in the controller? You should be able to: @model = Model.new(params[:model]) unless @model.valid? ... send your formatting message here ... end On Feb 10, 2:28 pm, KTU <ketuo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Jep I got it > > validates_format_of :intname, :with => /^[a-zA-Z0-9]*?$/, :message => > ''Internal > name can only contain letters & numbers and nospaces'' > > On Feb 10, 8:13 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On 10 Feb 2008, at 16:52, KTU wrote: > > > > Hi > > > > How I can check on models controller if item has space on it and if > > > yes then return error ? > > > > ie. on form you have textbox myitem and if users fills in there like: > > > xxx yyyy (ie. space on middle or end of value) > > > then this should return an error saying that no space is allowed on > > > that field ? > > > validates_format_of ? > > > Fred > > > > Thanks--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---