Dashboard > ActiveRecord > ... > Documentation > Validation
Validation
Added by Tim Haines, last edited by Daniel Rothmaler on Aug 20, 2007  (view change)
Labels: 
(None)



IMPORTANT NOTE: This page is massively out of date.  In RC3 all validators except for ValidateUnique where shifted to the ValidationComponent, and other ActiveRecord Validators were removed from the ActiveRecord project.  This page needs to be updated to reflect that.

Warning: There are some known issues yet to be resolved on using ARValidation with Session Scopes

You can combine validations on your ActiveRecord classes by using ActiveRecordValidationBase instead of ActiveRecordBase.

By doing so, you can use the following methods:

* IsValid: will return true only if all validation test passes
* ValidationErrorMessages: returns a string array of descriptive error messages

Validators

Currently we support the following validations:

* ValidateEmail
* ValidateIsUnique
* ValidateRegExp
* ValidateNonEmpty

It's easy to add your own, though.

Using it

[ActiveRecord]
public class Customer : ActiveRecordValidationBase
{
    private String contactName;
    private String phone;

    public Customer()
    {
    }

    [Property, ValidateNonEmpty]
    public string ContactName
    {
        get { return contactName; }
        set { contactName = value; }
    }

    [Property, ValidateNonEmpty]
    public string Phone
    {
        get { return phone; }
        set { phone = value; }
    }
}

If you attempt to save an invalid instance, AR will throw an exception, so calling IsValid is usually a good idea.

Site running on a free Atlassian Confluence Community License granted to Castle Project. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.4 Build:#809 Jun 12, 2007) - Bug/feature request - Contact Administrators