Giter Club home page Giter Club logo

dataannotationsextensions's People

Contributors

ctolkien avatar genexx avatar justinsa avatar patterson-philip avatar srkirkland avatar thieum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dataannotationsextensions's Issues

CreditCard attribute fails validation for specific dashes case

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.

Doesn't work in MVC 4 RC

Just adding it from NuGet and entering a view using data annotations results in this exception:

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

Numeric DataAnnotation not culturespecific

Is it possible to make the dataAnnotation numeric attribute specific to the currentculture info?
In my country decimal seperator is ',' instead of '.' As a result I cannot use the Numeric attribute you are providing

Date causes validation issues in chrome in the uk

I have a datetime field that i had decorated with the date annotation. having that validation caused chrome to not work with date fields (switching the culture info to american for some reason). don't want to even tell you how long it took me before i tried commenting out your attribute and everything started working

this was with the client side validation in asp.net mvc3

Localization needed

public override string FormatErrorMessage(string name)
{
if (ErrorMessage == null && ErrorMessageResourceName == null)
{
ErrorMessage = ValidatorResources.EmailAddressAttribute_Invalid;
}
...

Your standard error messages are not localizable in any way.

You should create a singleton that can be overridden in global.asax by user's own localization mechanism.
i.e. public class ValidationMessages {
public static ValidationMessages Instance { get; set; }
static ValidationMessages()
{
Instance = new ValidationMessages();
}

public virtual string EmailAddressAttribute_Invalid { get { return ValidatorResources.EmailAddressAttribute_Invalid; } }
....
}

This way I can override your implementation with my custom own - which could be another resource file or even another translation mechanism (i.e. using I18N .po files)

Exception thrown when setting ErrorMessageResourceName

I have not checked them all yet but DateAttribute and EmailAttribute appear to be broken when you set the ErrorMessageResourceName and ErrorMessageResourceType. The exception message is: Either ErrorMessageString or ErrorMessageResourceName must be set, but not both. I can assure you that I do not have both set. It occurs during page render. When I remove the ErrorMessageResourceName and ErrorMessageResourceType and provide no parameters to the attribute it works fine.

FileExtensions and HttpPostedFileBase

When binding to a model which uses HttpPostedFileBase validation will always fail because FileExtensions expects the property it is decorating to be string.

This should be simple to correct as all you would need to do is add a typeof check in FileExtensions IsValid method.

I'd be happy to create a pull request to fix this if you are happy with the idea of FileExtensions working when model binding to HttpPostedFileBase.

Numeric/Range interaction

[From Blog Comments, VincentG]

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!

Validation message override

I have a Messages.resx file in place with PropertyValueInvalid set to "*" and DefaultModelBinder.ResourceClassKey set to "Messages", which is the way one should change the default validation error string when posted value for certain property is invalid. Somehow the Email annotation extension attribute disregards this setup and still returns:

The [feedbackviewmodel_emailaddress] field is not a valid e-mail address.

What can be done about that? I have the described setup in place because that way I don't have to localize each and every property separately.

Client validation not working in VB

The client validation doesn't work in VB, though the server side does work. When checking in, I noticed:

App_Start\RegisterClientValidationExtensions.cs

which of course won't work in VB. I added these lines to my Application_Start function:

    DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(DataAnnotationsExtensions.EmailAttribute), GetType(DataAnnotationsExtensions.ClientValidation.Adapters.EmailAttributeAdapter))
    DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(DataAnnotationsExtensions.UrlAttribute), GetType(DataAnnotationsExtensions.ClientValidation.Adapters.UrlAttributeAdapter))
    DataAnnotationsModelValidatorProvider.RegisterAdapter(GetType(DataAnnotationsExtensions.DateAttribute), GetType(DataAnnotationsExtensions.ClientValidation.Adapters.DateAttributeAdapter))

and those 3 validations started working on the client side. So it looks like that's the problem, maybe a NuGet packaging issue.

YearAttribute

It would be cool with a YearAttribute which verifies an int for min (0001) and max (9999). A configurable boolean named EnforceDb (or something similar), could verify that the year is between min and max year in Sql Server.

Error Resources Tests Fail in Visual Studio 2012 RC

Test Name: ErrorResourcesTest
When running the tests from a clean pull and build in Visual Studio 2012 RC this error occurs in 12 of the tests:

Test FullName: DataAnnotationsExtensions.Tests.ValidationAttributes.CreditCardAttributeTests.ErrorResourcesTest
Test Source: c:\Users\ppatterson\GitHub\DataAnnotationsExtensions\DataAnnotationsExtensions.Tests\ValidationAttributes\CreditCardAttributeTests.cs : line 37
Test Outcome: Failed
Test Duration: 0:00:00.009912

Result Message: Assert.AreEqual failed. Expected:. Actual:.
Result StackTrace: at DataAnnotationsExtensions.Tests.ValidationAttributes.CreditCardAttributeTests.ErrorResourcesTest() in c:\Users\ppatterson\GitHub\DataAnnotationsExtensions\DataAnnotationsExtensions.Tests\ValidationAttributes\CreditCardAttributeTests.cs:line 46

In researching the issue I have discovered that the same thread is used to run all of the tests. The bug is created any time after running the tests named GlobalizedErrorResourcesTest in the same test run. If you run the tests separate from those they pass. Because the tests run in the same thread the call to:

System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-MX");

changes the result that is returned in the unrelated tests of ErrorResourcesTest. I am working on a patch now and will send a pull request later.

NuGet Package

Hey Scott,

Any chance of a new nuget release? I need the new HttpPostedFileBase support on the FileExtensionAttribute.

Cheers,
Ben

Digits Validator doesn't accept strings of arbitrary length

The Digits() validator is based on the Long.Parse() function, which limits the allowable strings to the maximum value a long value type can hold.

For example, an european account number of 21 digits will fail the validator.

Thank you

New Regex for Month & USZipCode

Month RegEx => private static Regex _regex = new Regex(@"^(?:J(anuary|u(ne|ly))|February|Ma(rch|y)|A(pril|ugust)|(((Sept|Nov|Dec)em)|Octo)ber)$");

USZipCode => private static Regex _regex = new Regex(@"^\d{5}$|^\d{5}-\d{4}$");

validator fires when first letter is entered

Hi Ive installed:

AppStart folder:
RegisterClientValidationExtensions.cs

using DataAnnotationsExtensions.ClientValidation;

[assembly: WebActivator.PreApplicationStartMethod(typeof(Mvc_WURFL_.ASPX.App_Start.RegisterClientValidationExtensions), "Start")]

namespace Mvc_WURFL_.ASPX.App_Start {
public static class RegisterClientValidationExtensions {
public static void Start() {
DataAnnotationsModelValidatorProviderExtensions.RegisterValidationExtensions();
}
}
}

Model:

[Required(ErrorMessage="Email Required")]

[RegularExpression(@"^((([a-z]|\d|[!#$%&'+-/=?^{|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(.([a-z]|\d|[!#\$%&'*+-\/=\?^_{|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+))|((\x22)((((\x20|\x09)(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))(((\x20|\x09)(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|.||~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))).)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|.||~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))).?$", ErrorMessage = "_Valid Email Required")]

    [DataType(DataType.EmailAddress)]
    public string Email { get; set; }

MasterPage.aspx:

<%= Scripts.Render("/bundles/jquery") %>
<%= Scripts.Render("
/bundles/jqueryval")%>

Sorry about all the code but thought to provide as much info as possible!

The issue is the Email Expression (*Valid Email Required) validator fires when first letter is entered, clientside not post back. All other validation working correctly.

Thought to ask the Master, many thanks Paul

DateTime server side validation

Using the following model property:

[Required(ErrorMessage = "Required")]
[Date(ErrorMessage = "Wrong format")]
[DataType(DataType.Date)]
public DateTime Date { get; set; }

With client side validation the messages "Required" and "Wrong format" are displayed as expected.
With only server side validation an empty input gives the expected "Required" validation message, but
wrong format gives the default "The value 'aaa' is not valid for Date.". I'd expect it to be "Wrong format".

Include Display Name in error message

I've been using your package for a couple of days. It's really useful.
However today I found a minor bug in the EqualTo attribute: it does not take the Display attribute of the property to compare into account.
For example:
[Display(Name = "Your password")]
public string Password {get; set}
[EqualTo("Password")]
public string Confirm {get;set;}

It will not take "Your password" into account.

Hope it will get fixed soon.

Regards

Quang

Adding UK Postcode validation

Hi,

I've, messily, added UK postcode (using government standard definition) to the project for internal use. If I tidy it up is it if interest me offering a pull back in?

Paul

NuGet Refresh

Is it possible to update the NuGet package to reflect the recent change to the CreditCardAttribute class concerning spaces?

ValidationSummary Not Displaying

Hi,

I am having an issue using the library where attributes that are validated client-side are causing the ValidationSummary to not display. The ValidationMesssage displays correctly, but the summary does not.

I've narrowed down the scenario that causes it to happen, I think. If you have an attribute that causes an error, such as email and you do something like the following, it will not display the summary:

@using (Html.BeginForm)
{

    @Html.ValidationSummary("Please correct the errors below")

    <div>@Html.TextBoxFor(m => m.Email) <div>@Html.ValidationMessageFor(m => m.Email)</div></div>

    <input type="submit />

}

Basically, if you put the validation message inside any block level element, such as div, p, etc. before ValidationMessage, the ValidationMessage will display, but the ValidationSummary will not.

If you add a 'Required' attribute, the built-in .Net attribute will trigger the summary, but if you type something to violate the email validation, that does not trigger the summary.

Any suggestions on how I can get around this issue?

I appreciate all the work on the library. It has saved us a ton of time on a project that we are working on.

Thanks in advance for your help.

Numeric ErrorMessage always shows default error message

Hi there,

I noticed with the numeric attribute if I try and put a custom error message it will always show the default error message

[Numeric(ErrorMessage="Custom error message should be shown")]
public double score { get; set; }

instead it displays:

The field score must be a number.

Regards DotnetShadow

Min attribute incorrectly fires when the minimum is a single digit

I have an integer property with the Min attribute set to 5. When using jQuery.unobtrusive validation plugin, jQuery will mark any value not starting with a 5 or greater as invalid and show the corresponding error message. Meaning the values 5 through 9 as well as 50-99, 500-999 etc all will pass validation. Any value not starting with a 5 or greater such as 10-49, 100-499, etc. will fail the javascript validation and display the error message. When the minimum is set to 10 or higher, the validation attributes all work as expected.

I confirmed this on a clean MVC 5 project using the following versions:

  • jQuery 1.8.2 and higher (including 2.x branch)
  • jQuery.validation - 1.11.0 (current as of this issue report)
  • jQuery unobtrusive validation 3.1.2 (current as of this issue report)

The work around is to use the Range() attribute within the .NET framework. Additional information located here - http://stackoverflow.com/questions/23687162/mvc-unobtrusive-validation-incorrectly-firing

Date GreaterThan/LessThan

Are there any plans to add date greater than / less than attributes? They've got something similar in foolproof.codeplex.com but I thought I would check here first.

MaxAttribute Incurrectly flags values as not in range

I set a max range of 110000, but it flags anything that has values of 11345 etc, it works if it matches 110000 etc. Maybe the regex or whatever your using should be:
"^0*(110,?000|((10[0-9]|[1-9][0-9]|[1-9]),?[0-9]{3})|([1-9][0-9]{2}|[1-9][0-9]|[1-9]))$

I'm passing values like 2500.00 or 231.00

They are decimal type and currency in the database.

EDIT:
After some digging on jquery.validate.js it appears that they already provide a max and min attribute and it uses there attribute to validate. However, it seems to fail when the value looks like "42.0000" if using currency or decimal.

If I take away the Quotes around it, then it works. I don't understand why this is happening.

// http://jqueryvalidation.org/max-method/
max: function( value, element, param ) {
return this.optional( element ) || value <= param;
},

Date Validation with German culture

In german cultures the date format is DD.MM.YYYY. Using the date data annotation extension the date formats as this when pre-populated with data but when you submit it does not accept full stops. It says 'The field DateOfBirth is not a valid date' until I change both full stops to forward slashes (/).

Date validation issue

Date validation fails in the following scenario. If we mention date like 12/31/20104 or 25/05/2014 validation is not firing.

Email DataAnnotations

Hi, I'm new to this but I think I found a bug with the email Data Annotation.

I have a property in a c# mvc model as follows:

    [DataType( DataType.EmailAddress )]
    [Display( Name = "Site Email:" )]
    [StringLength( 255 )]
    [Email( ErrorMessage = "Invalid Site Email Address" )]
    public string SiteEmail { get; set; } 

I have just implemented my views to either display or not display certain input fields on the web page. When I don't display this email address, and I post my View back, ModelState.IsValid is failing on this control. You can see that the property has no value, but for some reason, the error message returned is "Invalid Site Email Address".

DataAnnotationsExtensions MVC4

Hi, I'm trying to use the DataAnnotationsExtensions MVC nuget package with asp.net mvc4. I'm just wondering is its should be working with DataAnnotations but for some reasons I've having these following errors at run time.

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

I'm using it my models like...
[Date]
[ConditionalRequired("ProjectStatus")]
public DateTime ProjectCommencementDate { get; set; }

    [Date]
    [ConditionalRequired("ProjectStatus")]
    public DateTime ProjectCompletionDate { get; set; }

Can somebody guide me what I'm doing wrong here.

Date Validation issue

Date Annotation does not validate dates properly. It won't except numbers but if you type 91/12/5126, it will accept that as a valid date when it is not.

UrlOptions.OptionalProtocol doesn't work

Using it in ASP.NET MVC 5.1 project (haven't tried to reproduce it on earlier versions).

Have the following attribute applied:
[DataAnnotationsExtensions.Url(UrlOptions.OptionalProtocol)]
public string Domain { get; set; }

If I enter "domain.com" it says "Please enter a valid URL." I guess it conflicts with standard DataType.Url validation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.