I want to make my own validation class (i have a lot of validation methods in JS that i want to translate into C# to use with MVC models) that works exactly like data annotations do, validating in client and server side: [DataType(MyDataType)] or like a Validation DataAnnotation Attribute like this: [MyDataTypeValidation]
i don't know wich option is better to make my validation "library"
In example i have my class FigurasDA and i want to make my custom validation to the attribute nombre.
namespace MonitoreoIntegrado.Models
{
[MetadataType(typeof(FigurasDA))]
public partial class Figuras
{
}
public class FigurasDA
{
[DataType(MyDataType)]
//or
[MyDataTypeValidation]
public string nombre { get; set; }
}
}
so in this case, i want to validate that the string matches the regexp @"^[\w\s\.\-_]+$" and shows a error message like this "Solo se permite letras, numeros y puntuaciones(- _ .)" if don't. (this is my "Alfanumerico" datatype).
Can you give me an example where to put my validation class and what code write inside?.



RegularExpressionAttributeex:[RegularExpression(@"pattern", ErrorMessage="")]? Or you can extend one of theValidationAttributeclasses.