warrenbuckley / Umbraco-Validation-Attributes

This project is custom ASP.NET MVC Validation Attributes for Models, that allows error messages to be regionalised with dictionary items from Umbraco.
25 stars 9 forks source link

Phone #8

Open warrenbuckley opened 10 years ago

warrenbuckley commented 10 years ago

http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.phoneattribute(v=vs.110).aspx

warrenbuckley commented 10 years ago

This is a sealed class so cannot inheritate, in two minds to do this then. Thoughts @kholm ?

leekelleher commented 9 years ago

Bumping a bit of an old thread, but was curious how this might work out...

Wondering if this is the right approach?

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
public class UmbracoPhoneAttribute : DataTypeAttribute
{
    private static PhoneAttribute _wrapper = new PhoneAttribute();

    public UmbracoPhoneAttribute(string errorMessageDictionaryKey)
        : base(DataType.PhoneNumber)
    {
        this.ErrorMessage = UmbracoValidationHelper.GetDictionaryItem(errorMessageDictionaryKey);
        _wrapper.ErrorMessage = this.ErrorMessage;
    }

    public override bool IsValid(object value)
    {
        return _wrapper.IsValid(value);
    }
}

Not that I need this code myself at the moment, just had a programmer's itch to scratch ;-)

For reference, the source for PhoneAttribute is here.

warrenbuckley commented 9 years ago

Hey @leekelleher this looks perfectly good to me mate and I would love a Pull Request if you want to do it.

I need to make/find time as there is an issue with these in a newer version of 7 as described on issue tracker, but as always I can never find the time to give all projects love, care & attention they need. So any contributions is more than welcome :+1:

leekelleher commented 9 years ago

@warrenbuckley I know exactly what you mean - I'm facing the same on my various projects :bowtie:

I'll see what I can do! :metal: