Wednesday, February 23, 2011 8:12 AM srkirkland

Introducing Data Annotations Extensions

Validation of user input is integral to building a modern web application, and ASP.NET MVC offers us a way to enforce business rules on both the client and server using Model Validation.  The recent release of ASP.NET MVC 3 has improved these offerings on the client side by introducing an unobtrusive validation library built on top of jquery.validation.  Out of the box MVC comes with support for Data Annotations (that is, System.ComponentModel.DataAnnotations) and can be extended to support other frameworks.  Data Annotations Validation is becoming more popular and is being baked in to many other Microsoft offerings, including Entity Framework, though with MVC it only contains four validators: Range, Required, StringLength and Regular Expression.  The Data Annotations Extensions project attempts to augment these validators with additional attributes while maintaining the clean integration Data Annotations provides.

A Quick Word About Data Annotations Extensions

The Data Annotations Extensions project can be found at http://dataannotationsextensions.org/, and currently provides 11 additional validation attributes (ex: Email, EqualTo, Min/Max) on top of Data Annotations’ original 4.  You can find a current list of the validation attributes on the afore mentioned website.

The core library provides server-side validation attributes that can be used in any .NET 4.0 project (no MVC dependency). There is also an easily pluggable client-side validation library which can be used in ASP.NET MVC 3 projects using unobtrusive jquery validation (only MVC3 included javascript files are required).

On to the Preview

Let’s say you had the following “Customer” domain model (or view model, depending on your project structure) in an MVC 3 project:

public class Customer
{
    public string  Email { get; set; }
    public int Age { get; set; }
    public string ProfilePictureLocation { get; set; }
}

When it comes time to create/edit this Customer, you will probably have a CustomerController and a simple form that just uses one of the Html.EditorFor() methods that the ASP.NET MVC tooling generates for you (or you can write yourself).  It should look something like this:

image

With no validation, the customer can enter nonsense for an email address, and then can even report their age as a negative number!  With the built-in Data Annotations validation, I could do a bit better by adding a Range to the age, adding a RegularExpression for email (yuck!), and adding some required attributes.  However, I’d still be able to report my age as 10.75 years old, and my profile picture could still be any string.  Let’s use Data Annotations along with this project, Data Annotations Extensions, and see what we can get:

public class Customer
{
    [Email]
    [Required]
    public string  Email { get; set; }
 
    [Integer]
    [Min(1, ErrorMessage="Unless you are benjamin button you are lying.")]
    [Required]
    public int Age { get; set; }
 
    [FileExtensions("png|jpg|jpeg|gif")]
    public string ProfilePictureLocation { get; set; }
}

Now let’s try to put in some invalid values and see what happens:

image

That is very nice validation, all done on the client side (will also be validated on the server).  Also, the Customer class validation attributes are very easy to read and understand.

Another bonus: Since Data Annotations Extensions can integrate with MVC 3’s unobtrusive validation, no additional scripts are required!

Now that we’ve seen our target, let’s take a look at how to get there within a new MVC 3 project.

Adding Data Annotations Extensions To Your Project

First we will File->New Project and create an ASP.NET MVC 3 project.  I am going to use Razor for these examples, but any view engine can be used in practice. 

Now go into the NuGet Extension Manager (right click on references and select add Library Package Reference) and search for “DataAnnotationsExtensions.”  You should see the following two packages:

image

The first package is for server-side validation scenarios, but since we are using MVC 3 and would like comprehensive sever and client validation support, click on the DataAnnotationsExtensions.MVC3 project and then click Install.  This will install the Data Annotations Extensions server and client validation DLLs along with David Ebbo’s web activator (which enables the validation attributes to be registered with MVC 3).

Now that Data Annotations Extensions is installed you have all you need to start doing advanced model validation.  If you are already using Data Annotations in your project, just making use of the additional validation attributes will provide client and server validation automatically.  However, assuming you are starting with a blank project I’ll walk you through setting up a controller and model to test with.

Creating Your Model

In the Models folder, create a new User.cs file with a User class that you can use as a model.  To start with, I’ll use the following class:

public class User
{
    public string Email { get; set; }
    public string Password { get; set; }
    public string PasswordConfirm { get; set; }
    public string HomePage { get; set; }
    public int Age { get; set; }
}

Next, create a simple controller with at least a Create method, and then a matching Create view (note, you can do all of this via the MVC built-in tooling).  Your files will look something like this:

UserController.cs:

public class UserController : Controller
{
    public ActionResult Create()
    {
        return View(new User());
    }
 
    [HttpPost]
    public ActionResult Create(User user)
    {
        if (!ModelState.IsValid)
        {
            return View(user);
        }
 
        return Content("User valid!");
    }
}

Create.cshtml:

@model NuGetValidationTester.Models.User
 
@{
    ViewBag.Title = "Create";
}
 
<h2>Create</h2>
 
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
 
@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>User</legend>
        
        @Html.EditorForModel()
        
        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

In the Create.cshtml view, note that we are referencing jquery validation and jquery unobtrusive (jquery is referenced in the layout page).  These MVC 3 included scripts are the only ones you need to enjoy both the basic Data Annotations validation as well as the validation additions available in Data Annotations Extensions.  These references are added by default when you use the MVC 3 “Add View” dialog on a modification template type.

Now when we go to /User/Create we should see a form for editing a User

image

Since we haven’t yet added any validation attributes, this form is valid as shown (including no password, email and an age of 0).  With the built-in Data Annotations attributes we can make some of the fields required, and we could use a range validator of maybe 1 to 110 on Age (of course we don’t want to leave out supercentenarians) but let’s go further and validate our input comprehensively using Data Annotations Extensions.  The new and improved User.cs model class.

{
    [Required]
    [Email]
    public string Email { get; set; }
 
    [Required]
    public string Password { get; set; }
 
    [Required]
    [EqualTo("Password")]
    public string PasswordConfirm { get; set; }
 
    [Url]
    public string HomePage { get; set; }
 
    [Integer]
    [Min(1)]
    public int Age { get; set; }
}

Now let’s re-run our form and try to use some invalid values:

image

All of the validation errors you see above occurred on the client, without ever even hitting submit.  The validation is also checked on the server, which is a good practice since client validation is easily bypassed.

That’s all you need to do to start a new project and include Data Annotations Extensions, and of course you can integrate it into an existing project just as easily.

Nitpickers Corner

ASP.NET MVC 3 futures defines four new data annotations attributes which this project has as well: CreditCard, Email, Url and EqualTo.  Unfortunately referencing MVC 3 futures necessitates taking an dependency on MVC 3 in your model layer, which may be unadvisable in a multi-tiered project.  Data Annotations Extensions keeps the server and client side libraries separate so using the project’s validation attributes don’t require you to take any additional dependencies in your model layer which still allowing for the rich client validation experience if you are using MVC 3.

Custom Error Message and Globalization: Since the Data Annotations Extensions are build on top of Data Annotations, you have the ability to define your own static error messages and even to use resource files for very customizable error messages.

Available Validators: Please see the project site at http://dataannotationsextensions.org/ for an up-to-date list of the new validators included in this project.  As of this post, the following validators are available:

  • CreditCard
  • Date
  • Digits
  • Email
  • EqualTo
  • FileExtensions
  • Integer
  • Max
  • Min
  • Numeric
  • Url

Conclusion

Hopefully I’ve illustrated how easy it is to add server and client validation to your MVC 3 projects, and how to easily you can extend the available validation options to meet real world needs.

The Data Annotations Extensions project is fully open source under the BSD license.  Any feedback would be greatly appreciated.  More information than you require, along with links to the source code, is available at http://dataannotationsextensions.org/.

Enjoy!

Filed under: , , , , , , , ,

Comments

# re: Introducing Data Annotations Extensions

Thursday, February 24, 2011 6:47 AM by André Castro

I'm gonna try this one, looks very nice and simple. Thanks!

# re: Introducing Data Annotations Extensions

Thursday, February 24, 2011 6:50 AM by Ross

Can I use this in an existing MVC 2.0 app?

# re: Introducing Data Annotations Extensions

Thursday, February 24, 2011 8:13 AM by Kevin Priester

I am loading this one up right now.

# re: Introducing Data Annotations Extensions

Thursday, February 24, 2011 9:54 AM by Zach Curtis

Great post, cannot wait to try it out!

How come referencing MVC 3 is not advisable in the Model layer?

# re: Introducing Data Annotations Extensions

Thursday, February 24, 2011 2:38 PM by srkirkland

@Zach,

>Great post, cannot wait to try it out!

>

>How come referencing MVC 3 is not advisable in the Model layer?

It really depends -- if you are using ViewModels then it would probably be fine, but lots of people might have their domain objects in a separate assembly and not want that library to reference MVC.  The key is you have the flexibility to separate out your models from MVC and still get all of the benefits of client/server validation, if that's what you would like to do.

# re: Introducing Data Annotations Extensions

Wednesday, March 2, 2011 10:04 PM by James Manning

Any chance you would be willing to include Silverlight support?  The target scenario being WCF RIA services, adding these new annotations on the server side (via metadata class for EF, or directly for POCO, or whatever) and then have it work on the (silverlight) client side too when the client-side proxy code is generated.

Thanks!

# re: Introducing Data Annotations Extensions

Monday, March 7, 2011 7:02 AM by WolfyUK

This looks great.

Would it be possible to support cultures other than the invariant for the parsing of digits and dates in a future version?

# re: Introducing Data Annotations Extensions

Monday, March 7, 2011 2:00 PM by srkirkland

@Ross,

>Can I use this in an existing MVC 2.0 app?

The server-side validation attributes will work in a MVC 2.0 application (or any .NET 4 application), but the client-side package utilizes the unobtrusive jQuery validation which was only introduced in MVC 3.

# re: Introducing Data Annotations Extensions

Monday, March 7, 2011 2:05 PM by srkirkland

@WolfyUK,

>This looks great.

>Would it be possible to support cultures other than the invariant for >the parsing of digits and dates in a future version?

That is a great idea-- I've created an issue ticket for this at the project GitHub repository and I'll look into adding culture support for future versions.

github.com/.../2

# re: Introducing Data Annotations Extensions

Wednesday, March 9, 2011 1:01 AM by srkirkland

@WolfyUK,

>This looks great.

>Would it be possible to support cultures other than the invariant for >the parsing of digits and dates in a future version?

Version 0.3 on NuGet now supports using the current culture for date and number formatting on the server.

For client-side globalization support you can simply use any existing method for extending jQuery validate, possibly using the Microsoft jQuery globalization plugin.

# re: Introducing Data Annotations Extensions

Wednesday, March 9, 2011 10:38 AM by Quang Vo

There's a problem with EqualTo attribute. It does not take Display attribute of the target property (the property to compare with) into account. Please fix this.

# re: Introducing Data Annotations Extensions

Wednesday, March 9, 2011 6:00 PM by neilm

Am I correct in thinking that currently the DateAttribute is fixed against the mm/dd/yyyy format?

# re: Introducing Data Annotations Extensions

Wednesday, March 9, 2011 6:38 PM by srkirkland

@neilm,

>Am I correct in thinking that currently the DateAttribute is fixed >against the mm/dd/yyyy format?

No, actually the server-side validation is culture aware and will parse any date format that .NET knows.  Client-side validation uses the JavaScript date object to determine validity, and additionally (if you really need to) you can easily override jQuery validation's date rule at any time (possibly using a plugin like jQuery globalization).

# re: Introducing Data Annotations Extensions

Wednesday, March 16, 2011 1:13 AM by srkirkland

@Quang Vo,

>There's a problem with EqualTo attribute. It does not take Display attribute of the target property (the property to compare with) into account. Please fix this.

   I've looked into this and it turns out getting the client-side validation message to respect a display name is really easy (by hooking into the MVC model metadata provider), but for the server-side validation message you don't have access to the model metadata because it is not passed by MVC's default Data Annotations Model Validator, so the best you can do is manually checking for a [Display] attribute (which ties you to data annotations model metadata only).  This works fairly well, but I don't think it's flexible enough to go into the master branch (which may be why the MVC team has the same issue with their [Compare] attribute).  However, since the changes would be fairly simple (just 2 files need updating) I've made them available at https://gist.github.com/872037 in case you would like to make the changes in a fork.

# re: Introducing Data Annotations Extensions

Wednesday, April 6, 2011 7:57 PM by Rob Martinez

Have been searching all over for an answer to a lingering question I have when I stumbled upon your great project: how can I display a success and/or failure image with the validation message inside.  I know I can use CSS to display a background image, the problem is its a static image and longer messages won't work.  I find myself trying to keep my messages to a fixed length, which is always not practical.  Also, on at least one occasion, one field has two messages which display upon failure and which always are longer than the fixed image.  I tried using <div>'s to surround the ValdiationMessage, but then the images are always present (they work great when a message does fire) - also, a success image won't work in that scenario.

I later tried to create extensions, but was unable to figure out how to change the <span> to a set of <div's>.  The more I think about it the more that last idea sounds best, as it gives me total control.  But is it doable?

Thanks for any advice or pointing me in the right direction.

# re: Introducing Data Annotations Extensions

Monday, April 11, 2011 3:36 AM by Jeremy Lundy

Looks pretty good. One thing I noticed with your CreditCardAttribute (and MVC Futures!) is that a string containing only hyphens will pass validation. There should be a check for an empty string after removing hyphens:

ccValue = ccValue.Replace("-", "");

if (string.IsNullOrEmpty(ccValue))

{

 return false;

}

This is safe because you have already returned true if the value was null at the beginning of the method.

I will probably post the same issue on Codeplex for MVC Futures.

# re: Introducing Data Annotations Extensions

Thursday, April 28, 2011 11:17 AM by Steven Archibald

I'm looking for this using VS 2010, and cannot find it at all.  I have NuGet for VS installed ...

# re: Introducing Data Annotations Extensions

Friday, April 29, 2011 4:55 PM by srkirkland

@Steven Archibald,

  Go to dataannotationsextensions.org/.../Download for direct links to the nuget packages.  Also, I've always found searching by "data annotations" in the NuGet VS2010 plugin will cause the packages to show up at the first options.

# re: Introducing Data Annotations Extensions

Tuesday, May 10, 2011 2:02 AM by nnsca

You may want to add the BooleanRequired annotation referenced in this post

itmeze.com/.../checkbox-has-to-be-checked-with-unobtrusive-jquery-validation-and-asp-net-mvc-3

# re: Introducing Data Annotations Extensions

Wednesday, May 11, 2011 4:29 AM by TonyW

Just about to write all of this myself when I stumbled across your project.  Fantastic project and great work.  Saved me hours of work!!

# re: Introducing Data Annotations Extensions

Thursday, May 26, 2011 5:43 AM by Anand More

Hi,

I am adding the reference of Data Annotations Extensions in MVC3 using VB.net project and i found this is not working.

I cannot getting any error when i add the attribute in property e.g.

<Required()> _

       <Display(Name:="Email Address *")> _

       <Email(ErrorMessage:="Invalid Email Address")> _

       Public Property EmailAddress() As String

           Get

               Return m_EmailAddress

           End Get

           Set(ByVal value As String)

               m_EmailAddress = value

           End Set

       End Property

but the field is not getting validated , its validated for required field but not validated for valid email address.

Please let me know what is wrong i am doing...

# re: Introducing Data Annotations Extensions

Thursday, May 26, 2011 7:52 AM by Anand More

Hi again....

I just tried Data Annotations Extensions using MVC 3 using c#.net and its working fine...

This means Data Annotations Extensions is not working in MVC 3 VB.net...

I am planning to use this in actual project (MVC 3 using VB.net) , please help...

Anand More

India, Pune.

# re: Introducing Data Annotations Extensions

Tuesday, June 7, 2011 9:55 AM by Al

So, for a date annotation, how do I also specify a date format for existing values?

[Date(ErrorMessage = "Please enter a valid date.")]

   [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "dd-MMM-yy")]

is an utter fail cake

makes this project a bag of spanners imo

# re: Introducing Data Annotations Extensions

Wednesday, June 8, 2011 1:17 PM by srkirkland

@Al,

  The client-side validation is handled using the jquery.validation library, just as with ASPMVC as a whole.  Looking through the date validation code, it appears that jquery.validation uses the JavaScript "Date" class to parse the string and determine validity (thus date formats are irrelevant).  For more information, please see their site at bassistance.de/.../jquery-plugin-validation.  If you would like a very specific format, I'd suggest using the built in pattern validator.

# re: Introducing Data Annotations Extensions

Tuesday, June 21, 2011 8:17 AM by srkirkland

@Anand More,

  I'm not sure why it wouldn't work in VB since there is nothing language specific about the library, but I'll test it soon and see if I can reproduce your results.

Scott

# re: Introducing Data Annotations Extensions

Wednesday, July 27, 2011 9:56 AM by bhuvin.t

Could Required field Data Annotation work on collection ?

# re: Introducing Data Annotations Extensions

Friday, August 12, 2011 5:05 PM by Nick

I have the same problem as Anand More.  The email validation does not work in VB.NET MVC3.

Anand - Did you figure it out?  Any help would be greatly appreciated.

# re: Introducing Data Annotations Extensions

Wednesday, August 24, 2011 11:20 AM by rtyecript

I really liked the article, and the very cool blog

# re: Introducing Data Annotations Extensions

Wednesday, September 7, 2011 5:13 AM by Ron Del Rosario

The [Email] attribute works for expressions without the @ but fails when validating emails like ron@del. Anyone experience this?

# re: Introducing Data Annotations Extensions

Tuesday, September 13, 2011 4:01 AM by Vincent G

Hi Sir,

I am using your extensions for an ASP MVC3 VB project, and I really like the NumericAttribute extension, specifically because it can validate numeric strings with commas.

However when I combine NumericAttribute with, say, Range (built-in) or the extension's Min or Max, a weird thing happens. The Numeric test passes, but the range fails perhaps because of the comma.

In your sample site, for example, the MaxTenAndAHalf field, if you input -100000, it works. If you input -x, the correct error message appears: "The field MaxTenAndAHalf must be a number." Then, if you try -100,000... the error becomes: "The field MaxTenAndAHalf must be less than or equal to 10.5."

The same thing happens when I try to use the built-in Range annotation with the extension's Numeric attribute. As I would like to include commas in my application, is there any solution for the Range check to allow commas as well?

Thanks and have a nice day!

# re: Introducing Data Annotations Extensions

Friday, September 16, 2011 4:36 PM by flower-s

Could you please go more into detail how to use your NuGet package? I installed NuGet and Visual Studio Gallery and can't find your package. I don't understand how to get/use them from here nuget.org/.../DataAnnotationsExtensions.MVC3

Thanks.

# re: Introducing Data Annotations Extensions

Saturday, September 17, 2011 11:54 PM by srkirkland

@flower-s,

 Inside Visual Studio you can either Right-click on your project and select "Manage NuGet Packages" or open the Package Manager Console  (Tools->Library Package Manager->Package Manager Console).  If you are using the GUI search for "Data Annotations" and it will be the first result, if you are using the console you can just type in Install-Package DataAnnotationsExtensions.MVC3.  For great info on NuGet and how it works, see http://docs.nuget.org/.

# re: Introducing Data Annotations Extensions

Sunday, September 18, 2011 9:05 PM by srkirkland

@Ron Del Rosario,

>The [Email] attribute works for expressions without the @ but fails >when validating emails like ron@del. Anyone experience this?

ron@del is not a valid email address, and thus will fail email validation.  Can you give me an example of "expressions without the @" that pass validation?  

# re: Introducing Data Annotations Extensions

Thursday, September 29, 2011 4:27 AM by BaRRaK

Hi

To solve vb.net problems with client side validation you should register  the attributes.

It seems to no be added by default for vb.net project for a reason I don't understand.

Registering attributes works on my vb.net project :

       DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(NumericAttribute), GetType(NumericAttributeAdapter))

       DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(EmailAttribute), GetType(EmailAttributeAdapter))

       DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(UrlAttribute), GetType(UrlAttributeAdapter))

       DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(CreditCardAttribute), GetType(CreditCardAttributeAdapter))

       DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(EqualToAttribute), GetType(EqualToAttributeAdapter))

       DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(FileExtensionsAttribute), GetType(FileExtensionsAttributeAdapter))

       DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(NumericAttribute), GetType(NumericAttributeAdapter))

       DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(DigitsAttribute), GetType(DigitsAttributeAdapter))

       DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(MinAttribute), GetType(MinAttributeAdapter))

       DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(MaxAttribute), GetType(MaxAttributeAdapter))

       DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(DateAttribute), GetType(DateAttributeAdapter))

       DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(IntegerAttribute), GetType(IntegerAttributeAdapter))

# re: Introducing Data Annotations Extensions

Thursday, December 1, 2011 5:58 PM by rrrsr7205

Gor to the point of clicking on install of data annotations extensions mvc3 and the install began.

It terminated with an "Operation Failed" box, listing the following:

Id is required.

Version is required.

Authors is required.

Description is required.

I am stymied.  I cannot install it and thus cannot use it.  

How do I get the data annotations extension to install and what is the action to be taken in response to this "operation failed" notification?

# re: Introducing Data Annotations Extensions

Sunday, January 1, 2012 9:49 PM by Joe

I hate that I have to install NuGet just to downloada DLL. I think its BS that someone is foisting their opinion on me about how to tranfers bits from a server to my computer.  Total BS. Nice library though. NuGet is BS. I can right click and download just fine without it. BS.

# re: Introducing Data Annotations Extensions

Tuesday, January 10, 2012 9:48 PM by John Walker

I've used this package in a recent MVC/EF 4.1 project and it worked great. I'm now working on a Web Forms project with Dynamic Data controls and would like to use it. The .NET DataAnnotations work well with Dynamic Data Control validation, however, I really need your Date attribute. I've installed the package (non-MVC) into my library and I've decorated one of my properties with the [Date(ErrorMessage="Please enter a valid Birth Date")] attribute, but no joy.

Do you know of a way to get it to work with web forms/dynamic data controls? Would be great if it could.

Thanks for a great set of extensions.

# re: Introducing Data Annotations Extensions

Tuesday, February 14, 2012 1:26 AM by nivram509

I copied another validator from stackoverflow.com/.../validating-an-e-mail-address-with-unobtrusive-javascript-mvc3-and-dataannotati

and pasted it in to my project. I set a breakpoint in IsValid, and it never gets called.

I created my view with the wizard as a strongly typed view.

At the same time all the [Required] attributes work fine.

I'm baffled as how to get your attributes to work.

# re: Introducing Data Annotations Extensions

Wednesday, February 22, 2012 4:39 PM by Todd

Concerning the VB.net issue! Register these in the Global.asax.vb file.  in the Application_Start(). This worked for me. Thanks for the post and the tips.

"Hi

To solve vb.net problems with client side validation you should register  the attributes.

It seems to no be added by default for vb.net project for a reason I don't understand.

Registering attributes works on my vb.net project :

      DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(NumericAttribute), GetType(NumericAttributeAdapter))

      DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(EmailAttribute), GetType(EmailAttributeAdapter))

      DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(UrlAttribute), GetType(UrlAttributeAdapter))

      DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(CreditCardAttribute), GetType(CreditCardAttributeAdapter))

      DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(EqualToAttribute), GetType(EqualToAttributeAdapter))

      DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(FileExtensionsAttribute), GetType(FileExtensionsAttributeAdapter))

      DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(NumericAttribute), GetType(NumericAttributeAdapter))

      DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(DigitsAttribute), GetType(DigitsAttributeAdapter))

      DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(MinAttribute), GetType(MinAttributeAdapter))

      DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(MaxAttribute), GetType(MaxAttributeAdapter))

      DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(DateAttribute), GetType(DateAttributeAdapter))

      DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(IntegerAttribute), GetType(IntegerAttributeAdapter))

"

# re: Introducing Data Annotations Extensions

Saturday, March 17, 2012 11:19 PM by stevey

hi, scott, great post! I used NuGet to install the package successfully and got the email validator to run nicely in my local development project. but once I deployed to remote host (winhost.com), the client email validator stop working. Only server validator still functioned. any idea why? must i miss some components while deployed?

Thanks

steve

shigangy@hotmail.com

# re: Introducing Data Annotations Extensions

Sunday, March 18, 2012 1:36 AM by srkirkland

@stevey, Make sure you have script references to these required javascript files on your page: jquery, jquery.validation, and jquery.validate.unobtrusive. Also make sure your web.config has the default ClientValidationEnabled and UnobtrusiveJavaScriptEnabled appSettings keys set to true.

If all else fails look to see if one of the built-in MVC validators are working, like [Required]. Data Annotations Extensions doesn't require any additional references or configuration except for the one line (in App_Start) NuGet adds which registers the extensions, so if those work then [Email] and the other extensions should work.

Scott

# re: Introducing Data Annotations Extensions

Saturday, June 16, 2012 7:28 PM by Figo

I'm doing asp.net MVC3 project , In my class model (CarModel) , I putted an Integer attribute to validate property ModelYear, I tried to customize my error message based on localization , my code:

[Integer(ErrorMessageResourceName = "OnlyNumberValidator", ErrorMessageResourceType = typeof(AddNewCar))]

public Nullable<int> ModelYear { get; set; }

but it didn't take my error message and just shown the default message "The field ModelYear must be a number"

Note: it works on Required attribute !

# re: Introducing Data Annotations Extensions

Thursday, July 5, 2012 7:02 AM by Robert

Trying to use this in my MVC 4 project, installed from NuGet, but getting this:

Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required

# re: Introducing Data Annotations Extensions

Friday, August 10, 2012 1:25 PM by srkirkland

@Robert

I've tested that the current NuGet package will work fine in MVC4, using both .NET 4.0 and 4.5.  Additionally, I don't define the required validation type, so my guess is something else is messed up with your core MVC or DataAnnotations references.

>Trying to use this in my MVC 4 project, installed from NuGet, but getting this:

>Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required

# re: Introducing Data Annotations Extensions

Friday, August 10, 2012 1:26 PM by srkirkland

@Figo,

 Try changing model year to a string and the validation error message should kick in.  If you use a nullable int, then ASPNET MVC's default type checking will override any extensions and you won't get the custom error message

# re: Introducing Data Annotations Extensions

Friday, August 17, 2012 1:35 PM by Eduardo

Neverming, was blind and didnt see the big "fork me on Github"

# re: Introducing Data Annotations Extensions

Thursday, October 18, 2012 1:14 AM by Naom

Is it possible to add Phone extension?

# re: Introducing Data Annotations Extensions

Thursday, October 18, 2012 1:19 AM by Naom

The available formats should be all digits, 999-9999 and

(999) 999-9999 formats.

# re: Introducing Data Annotations Extensions

Tuesday, November 6, 2012 8:36 PM by Sweeney

If you desire to grow your experience just keep visiting this

web page and be updated with the latest information posted here.

# re: Introducing Data Annotations Extensions

Wednesday, November 28, 2012 11:24 PM by Canada Goose Jakker

Were there any exciting incidents during your journey? There go the house lights.Neither you nor he is wrong.On being introduced to somebody, a British person often shakes hands.I felt sort of ill.She makes it clear that she doesn't like swimming.She makes it clear that she doesn't like swimming.East,west£¬home is best.It seems all right.He set up a fine example to all of us.

# re: Introducing Data Annotations Extensions

Friday, November 30, 2012 7:23 PM by canadagoosenorgesale2012.webs.com/

How much money did you make?He knows English better than I.What horrible weather!I assure you that you will feel no pain at all.Don't fall for it!What be said did not annoy me much, for I knew he did not mean it.What be said did not annoy me much, for I knew he did not mean it.I have never seen the movie.Talking with you is a pleasure.Would you help me with the report?

# re: Introducing Data Annotations Extensions

Tuesday, December 4, 2012 7:36 AM by Canada Goose Trillium Parka Sort

We are prohibited from smoking on school grounds.What's your goal in life.Keep your temper under control.I guess I could come overI suppose you dance much.May I know the quantity you require? May I know the quantity you require? How's everything? He is only about five feet high.It's time for us to say “No” to America

# re: Introducing Data Annotations Extensions

Friday, December 14, 2012 7:20 PM by Lowtwera

you love this?  <a href="http://e--store.com/ ">coach online</a>  with confident   DXecrEjc  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Friday, December 14, 2012 7:55 PM by Priscimi

check this link, <a href="http://e--store.com/ ">coach bags outlet</a>   and get big save   KnxGmqAt  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Friday, December 14, 2012 8:19 PM by confiecy

get <a href="http://e--store.com/ ">coach outlet</a>  for more   qsJjbBAh  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Saturday, December 15, 2012 6:08 AM by erurtutt

buy best <a href="http://e--store.com/ ">coach online store</a>  with confident   HQAfOzjx  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Saturday, December 15, 2012 7:52 PM by Kesquire

click <a href="http://e--store.com/ ">coach online</a>  , just clicks away   uKloFXob  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Sunday, December 16, 2012 12:47 AM by Sheenous

click to view <a href="http://e--store.com/ ">coach outlet</a>  suprisely   QUMnlWlQ  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Sunday, December 16, 2012 6:29 PM by Thundfut

you love this?  <a href="http://e--store.com/ ">outlet coach</a>  for more detail   yZwaWEzN  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Sunday, December 16, 2012 7:35 PM by jeodully

get cheap <a href="http://e--store.com/ ">coach online</a>  with confident   PvltKCLI  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Monday, December 17, 2012 8:10 AM by Lowtwera

best for you <a href="http://e--store.com/ ">loui vuitton outlet</a>  for more   TlPTuufw  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Thursday, December 20, 2012 1:05 PM by GyncTund

click to view <a href="http://e--store.com/ ">louis vuitton online</a>  for gift   VAJWuPsG  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Saturday, December 22, 2012 7:18 PM by Sheenous

purchase <a href="http://e--store.com/ ">coach outlet sale</a>  to your friends   gmTuGsGR  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Sunday, December 23, 2012 4:01 PM by Thundfut

click to view <a href="http://e--store.com/ ">coach purse outlet</a>  suprisely   HvXNJgUp  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Sunday, December 23, 2012 8:08 PM by Feenepes

for <a href="http://e--store.com/ ">coach outlet</a>  online shopping   JnIwWztD  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Sunday, December 23, 2012 10:23 PM by binsseve

buy a <a href="http://e--store.com/ ">loui vuitton outlet</a>  at my estore   pMhvzZRt  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Monday, December 24, 2012 12:22 AM by binsseve

check <a href="http://e--store.com/ ">louis vuitton outlet online</a>   to get new coupon   oqltBPAt  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Monday, December 24, 2012 4:35 AM by cyncNask

to buy <a href="http://e--store.com/ ">coach purses outlet</a>  for more detail   HaOYaByk  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Tuesday, December 25, 2012 6:28 AM by Priscimi

you definitely love <a href="http://e--store.com/ ">coach outlet sale</a>   to take huge discount   cZRgzOJs  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Tuesday, December 25, 2012 12:10 PM by erurtutt

look at <a href="http://e--store.com/ ">lv outlet</a>  for more detail   vbRchdgz  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Wednesday, December 26, 2012 8:52 AM by confiecy

get <a href="http://e--store.com/ ">louis vuitton online outlet</a>  online shopping   HWagtqKw  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Wednesday, December 26, 2012 1:13 PM by Lowtwera

for <a href="http://e--store.com/ ">coach online</a>  for more   ZPwZuBDU  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Thursday, December 27, 2012 2:56 AM by Sheenous

I'm sure the best for you <a href="http://e--store.com/ ">coach purses outlet</a>  , just clicks away   KxLtJjxj  <a href="http://e--store.com/ "> http://e--store.com/ </a>

# re: Introducing Data Annotations Extensions

Tuesday, January 15, 2013 10:53 PM by Feedback

Does not allow localhost as a website address for [Url] annotation.

# re: Introducing Data Annotations Extensions

Wednesday, January 16, 2013 3:52 AM by Piazza

Hey there I am so grateful I found your web site, I really found you by

accident, while I was searching on Bing for something else, Regardless I am here

now and would just like to say cheers for a fantastic post

and a all round exciting blog (I also love the theme/design), I don’t have

time to read it all at the minute but I have saved it

and also included your RSS feeds, so when I have time I

will be back to read a lot more, Please do keep up the awesome jo.

# re: Introducing Data Annotations Extensions

Saturday, January 19, 2013 7:48 AM by Quiroz

I'm not sure where you are getting your info, but good topic. I needs to spend some time learning much more or understanding more. Thanks for magnificent information I was looking for this information for my mission.

# re: Introducing Data Annotations Extensions

Monday, February 4, 2013 5:00 AM by Yates

Hey! Do you know if they make any plugins to protect against hackers?

I'm kinda paranoid about losing everything I've worked hard on.

Any tips?

# re: Introducing Data Annotations Extensions

Monday, February 18, 2013 4:14 AM by Randle

Its such as you learn my thoughts! You seem to grasp so

much approximately this, like you wrote

the book in it or something. I believe that you

just can do with some p.c. to power the message house a bit,

but instead of that, this is magnificent blog. A great read.

I'll definitely be back.

# re: Introducing Data Annotations Extensions

Sunday, February 24, 2013 5:38 PM by Moran

It's very easy to find out any matter on net as compared to textbooks, as I found this post at this web site.

# re: Introducing Data Annotations Extensions

Sunday, February 24, 2013 5:57 PM by Turley

Hello colleagues, how is everything, and what

you want to say concerning this post, in my view its in

fact amazing in favor of me.

# re: Introducing Data Annotations Extensions

Tuesday, February 26, 2013 9:28 PM by Pierce

I have been browsing online more than three hours today, yet

I never found any interesting article like yours.

It's pretty worth enough for me. Personally, if all webmasters and bloggers made good content as you did, the net will be much more useful than ever before.

# re: Introducing Data Annotations Extensions

Thursday, February 28, 2013 3:48 PM by Mcmullin

It's genuinely very complex in this busy life to listen news on TV, therefore I only use web for that reason, and obtain the most up-to-date news.

# re: Introducing Data Annotations Extensions

Sunday, March 17, 2013 2:47 PM by Stover

Hi Dear, are you really visiting this web page regularly, if so after

that you will absolutely get pleasant knowledge.

# re: Introducing Data Annotations Extensions

Monday, March 18, 2013 5:24 AM by Newcomb

Very rapidly this website will be famous amid all blogging and site-building viewers, due to it's nice content

# re: Introducing Data Annotations Extensions

Monday, March 18, 2013 11:28 PM by Petersen

I love your blog.. very nice colors & theme. Did you make this website

yourself or did you hire someone to do it for you?

Plz reply as I'm looking to construct my own blog and would like to know where u got this from. kudos

# re: Introducing Data Annotations Extensions

Tuesday, March 19, 2013 4:50 PM by Wyant

When someone writes an article he/she retains the idea of a user in his/her brain that how a user

can know it. Therefore that's why this paragraph is outstdanding. Thanks!

# re: Introducing Data Annotations Extensions

Friday, March 22, 2013 1:23 AM by Brubaker

You actually make it seem so easy with your presentation but I find this topic to be actually something which I think I would never understand.

It seems too complex and extremely broad for me.

I'm looking forward for your next post, I'll try to

get the hang of it!

# re: Introducing Data Annotations Extensions

Friday, March 22, 2013 3:46 AM by Crum

My developer is trying to convince me to move to .net from

PHP. I have always disliked the idea because of the costs.

But he's tryiong none the less. I've been using Movable-type on several websites

for about a year and am concerned about switching to another platform.

I have heard very good things about blogengine.net. Is there a way I can import all my

wordpress content into it? Any help would be really appreciated!

# re: Introducing Data Annotations Extensions

Friday, March 22, 2013 6:55 AM by Solomon

Pretty component to content. I just stumbled upon your web site and in accession capital to claim that I get in fact loved account your

blog posts. Any way I will be subscribing in your feeds and even I achievement

you access constantly quickly.

# re: Introducing Data Annotations Extensions

Friday, March 22, 2013 10:40 AM by Cody

Hello there! This is my first visit to your blog! We are a team of volunteers and starting a new project in a community

in the same niche. Your blog provided us useful information to

work on. You have done a outstanding job!

# re: Introducing Data Annotations Extensions

Friday, March 22, 2013 12:57 PM by Ivey

Hi there! This is my first visit to your blog!

We are a collection of volunteers and starting a

new project in a community in the same niche. Your blog

provided us useful information to work on. You have done a outstanding job!

# re: Introducing Data Annotations Extensions

Friday, March 22, 2013 8:50 PM by Rawls

I could not refrain from commenting. Well written!burberry outlet store

# re: Introducing Data Annotations Extensions

Friday, March 22, 2013 10:32 PM by Carson

I've been surfing online more than 4 hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. Personally, if all webmasters and bloggers made good content as you did, the internet will be much more useful than ever before.spyder Snowboarding Jackets

# re: Introducing Data Annotations Extensions

Sunday, March 31, 2013 1:27 AM by Kline

Superb, what a webpage it is! This website gives useful data to us, keep it up.

# re: Introducing Data Annotations Extensions

Saturday, April 6, 2013 4:52 PM by Albright

Oh my goodness! Awesome article dude! Thanks,

However I am going through problems with your RSS.

I don't understand the reason why I can't join it. Is there anybody else getting the same

RSS problems? Anybody who knows the solution can you kindly respond?

Thanx!!

# re: Introducing Data Annotations Extensions

Friday, April 12, 2013 7:11 PM by Carbone

I truly love your site.. Pleasant colors & theme.

Did you develop this amazing site yourself?

Please reply back as I'm wanting to create my very own site and would like to know where you got this from or exactly what the theme is named. Thanks!

# re: Introducing Data Annotations Extensions

Sunday, April 21, 2013 11:38 AM by Simon

When some one searches for his vital thing,

therefore he/she wishes to be available that in detail, so that thing is maintained over here.

# re: Introducing Data Annotations Extensions

Monday, May 6, 2013 9:57 PM by mdvsqvgm@live.com

designer physique whey protein

# re: Introducing Data Annotations Extensions

Saturday, May 11, 2013 8:17 PM by Duckett

In addition, some fabric coolers have multiple or outside zipper pockets and mesh sleeves to hold utensils, napkins,

and then any other small accessory items. Similarly, chronic

sinus infections and allergies can have the same effect -- they constantly extend the skin

because area, and finally it becomes loose. If you're artistic, you will like the colors with the covers.

# re: Introducing Data Annotations Extensions

Thursday, May 16, 2013 5:18 PM by Madrigal

That is a great tip especially to those fresh to the blogosphere.

Simple but very precise information… Many thanks for sharing this one.

A must read article!

# re: Introducing Data Annotations Extensions

Wednesday, May 22, 2013 6:50 PM by ojybtzwygmail.com

hello.thanks for your posted,i really love your site,thanks

# re: Introducing Data Annotations Extensions

Wednesday, May 22, 2013 6:52 PM by fvzjmiugmail.com

hello.thanks for your posted,i really love your site,thanks

# re: Introducing Data Annotations Extensions

Wednesday, May 22, 2013 9:22 PM by cyqrdqqhimxgmail.com

hello.thanks for your posted,i really love your site,thanks