check if space exists on the value and if yes prompt for error

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

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

Jep I got it

validates_format_of :intname, :with => /^[a-zA-Z0-9]*?$/, :message => 'Internal name can only contain letters & numbers and nospaces'

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