validations

Friendly Form Validations (Rails)

I checked out both of these previously-asked questions, and they're a help but not a full solution for my case. Essentially I need to validate a user-submitted URL from a form. I've started by validating that it begins with http://, https://, or ftp:// : class Link < ActiveRecord::Base validates_format_of [:link1, :link2, :link3, ...

How to use form_remote_tag together with validations?

I would like to have Ajax form in Rails so i'm using form_remote_tag. The field i would like to submit is email address - how can i use the Rails validations together with form_remote_tag? ...

Rails Validation Issue

OK, so I'm really new to Ruby on Rails. I'm using InstantRails, if that is going to make any difference. Here is my problem- I am trying to validate some entries into a form. If I use the form without any validations, then it works fine. If I add the validations, it completely changes the application's behavior and does not work. For ...

Validating length of habtm association without saving.

I have a user model with a HABTM relationship to groups. I do not want a user to be able to be in more than 5 groups, so would like to validate the length of the HABTM relationship. On the edit user page I have a list of checkboxes where the user can select the groups they want to be in (I'm using formtastic for the form). In my users...

How do you validate the presence of one field from many

I'm answering my own questions - just putting this up here for google-fu in case it helps someone else. This code allows you to validate the presence of one field in a list. See comments in code for usage. Just paste this into lib/custom_validations.rb and add require 'custom_validations' to your environment.rb #good post on how to d...

How to override html formatting in validation errors in Rails?

I'm wondering if there's a way to remove the formatting created by rails validations? My HTML is below, but basically if there's an error it'll format my errors in the built-in rails way... yet I'd like to have it not. For example, in the below, the password_field would be formatted differently in the event of an error (I don't want th...

Smarter paperclip validations

I'm using paperclip in a rails app and have the following three validations in my model validates_attachment_presence :photo validates_attachment_size :photo, :less_than=>1.megabyte validates_attachment_content_type :photo, :content_type=>['image/jpeg', 'image/png', 'image/gif'] If the user forgets to add an attac...

Rails validations. Needs data from other stuff. Multiple forms. Not being DRY

(Rails newbie) Hello! I am feeling like I am reusing a lot of my code and I feel there has to be a better way to do this... (I am sure there is...) What I have is a Settings page, where you can create categories and procedures (which belong to a category). index Settings action: def categories_and_procedures @prefs = @current...

Ruby on Rails: Is it better to validate in the model or the database?

Is it generally better practice (and why) to validate attributes in the model or in the database definition? For (a trivial) example: In the user model: validates_presence_of :name versus in the migration: t.string :name, :null => false On the one hand, including it in the database seems more of a guarantee against any type of b...

How to validate integer and float input in asp.net textbox

I am using below code to validate interger and float in asp.net but if i not enter decimal than it give me error <asp:TextBox ID="txtAjaxFloat" runat="server" /> <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" TargetControlID="txtAjaxFloat" FilterType="Custom, numbers" ValidChars="." runat="server" /> i have this r...

enabling disabling asp.net validation controls using jquery

hello, plz guide me how I can enable or disable asp.net validation controls using jQuery from client side. It is required to do so that valdiations can be done on button press. thanks ...

Validate Mobile Number

I want to have a mobile number validate for my site not just string validations ..what i need is to actually validate the mobile number with the same user exists.. one option i know is to send a pin to that mobile number & ask user to put that pin on form submit to validate ...so are there any ready to use services for this to use it on...

rails + rspec : Staying DRY when testing validations

Ok say I have the following model: class Country < ActiveRecord::Base validates_presence_of :name validates_presence_of :code end I'm doing the rspec unit tests for those validations. They look like this: it "should be invalid without a name" do country = Country.new(@valid_attributes.except(:name)) country.should_not b...

Rails 3: Validate combined values

In Rails 2.x you can use validations to make sure you have a unique combined value like this: validates_uniqueness_of :husband, :scope => :wife In the corresponding migration it could look like this: add_index :family, [:husband, :wife], :unique => true This would make sure the husband/wife combination is unique in the database. No...

Jquery validations on form with no fields

I have a table (in a form) populated with radio buttons (with a button for each value in a collection). If the collection is empty, nothing shows up in the table (which is fine). (I'm using Struts2) My trouble comes when validating that the user has selected one of these radio buttons when the submit button is clicked. I'm using JQUE...

Two models, one STI and a Validation

Let's say I have two tables -- Products and Orders. For the sake of simplicity assume that only one product can be purchased at a time so there is no join table like order_items. So the relationship is that Product has many orders, and Order belongs to product. Therefore, product_id is a fk in the Order table. The product table is ST...

ASP.NET button click event still firing even through custom server-side validation fails

I am having a problem where my button click event is still firing even though my custom server-side validation is set to args.IsValid = false. I am debugging through the code and the validation is definitely being fired before the button click, and args.IsValid is definitely being set to false once the custom validation takes place, but ...

ASP.NET: What's the best way to validate 3 drop downs boxes that are used to select a date (month, day, year)?

I have two sets of drop downs for start date and end date. Each date is created by selecting a month, day, and year from 3 separate drop downs. I currently have RequiredFieldValidators on all the drop downs (which just shows a * if nothing has been selected yet), but I need to validate that the end date is greater than the start date. I ...

Do validations still fire in ASP.NET even if the controls are hidden?

I have a form that uses ASP.NET validations. I am using some inline C# in the aspx to show/hide certain controls depending on a user's role. I would use the Visible property, but there are so many of them, I just decided to do inline C# to show and hide (I know, not best practice, but bear with me for a second). I am having an issue wher...

How do I set a Rails validation to ensure that two attributes can't have the same value?

I have a form on my site that lets users direct a message at other users, but I want to ensure that they can't direct a message at themselves. The class has attributes :username and :target_user, and I just want to set a validation that checks to make sure that these attributes can't have the same value, before anything gets saved. I f...