Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.ComponentModel.DataAnnotations;
- using System.Linq;
- [MetadataType(typeof (FooBarMetaData))]
- public class FooBar
- {
- // Insert FooBar related properties, methods, etc. here
- private sealed class FooBarMetaData
- {
- [DisplayName("First Name")]
- [Required(ErrorMessage = "<b>First Name</b> is required")]
- [StringLength(50, ErrorMessage = "<b>First Name</b> cannot exceed 50 characters")]
- public string FirstName{ get; set; }
- [DisplayName("Last Name")]
- [Required(ErrorMessage = "<b>Last Name</b> is required")]
- [StringLength(50, ErrorMessage = "<b>Last Name</b> cannot exceed 50 characters")]
- public string LastName{ get; set; }
- [DisplayName("Email")]
- [Required(ErrorMessage = "<b>Email</b> is required")]
- [EmailValidator(ErrorMessage = "Invalid email address")]
- public string EmailAddress{ get; set; }
- [DisplayName("Location")]
- [Required(ErrorMessage = "<b>Location</b> is required")]
- [StringLength(50, ErrorMessage = "<b>Location</b> cannot exceed 50 characters")]
- public string Location{ get; set; }
- }
- }
- public class EmailValidatorAttribute : ValidationAttribute
- {
- public override bool IsValid(object value)
- {
- if (value == null)
- return false;
- bool isValidEmail;
- // Insert logic here to validate the email address
- return isValidEmail;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment