Last active
November 10, 2019 19:52
-
-
Save Legends/ca0678d533601816fcb90eef63648812 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.ComponentModel.DataAnnotations; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using Microsoft.AspNetCore.Mvc; | |
| using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; | |
| using Microsoft.AspNetCore.Mvc.Rendering; | |
| /// <summary> | |
| /// Developer console: --> $.validator.unobtrusive.adapters | |
| /// Lists all available clientside validation functions | |
| /// </summary> | |
| public class JobApplication | |
| { | |
| [Required(ErrorMessage = "NameRequired")] | |
| [Display(Name = "Job applicant name")] | |
| [NameValidateAttribute(NotAllowed = new string[] { "Osama Bin Laden", "Saddam Hussain", "Mohammed Gaddafi" }, ErrorMessage = "ForbiddenPerson")] | |
| public string Name { get; set; } | |
| [CustomDate] //<-- custom attribute | |
| // https://stackoverflow.com/a/9519493/2581562 | |
| // must be in format yyyy-mm-dd | |
| [Required(ErrorMessage = "Required")] | |
| //[Remote("ValidateDate", "Job", ErrorMessage = "DOB")] | |
| public DateTime DOB { get; set; } | |
| [Required(ErrorMessage = "SexRequired")] | |
| public string Sex { get; set; } | |
| [DataType(DataType.Currency, ErrorMessage = "Currency")] | |
| [Required(ErrorMessage = "Required")] | |
| [CurrencyMustMeetCulture(ErrorMessage = "Currency")] | |
| public decimal Price { get; set; } | |
| [Required(ErrorMessage = "Required")] | |
| [Range(1, 6, ErrorMessage = "RangeAllowed")] | |
| [RegularExpression(@"^[1-6]{1}$", ErrorMessage = "RangeAllowed")] | |
| public int Experience { get; set; } | |
| //[Range(typeof(bool), "true", "true", ErrorMessage = "You must accept the Terms")] <-- doesn't work as expected | |
| [MustBeTrue(ErrorMessage = "AcceptTerms")] | |
| public bool TermsAccepted { get; set; } | |
| [RegularExpression("^[a-zA-Z0-9_\\.-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$", ErrorMessage = "EmailValid")] | |
| public string Email { get; set; } | |
| /// <summary> | |
| /// Keeps the items for the select -> options dropdownlist | |
| /// </summary> | |
| [ValidateNever] | |
| public SelectList ExperienceSelectOptions { get; set; } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment