■ RegularExpressionAttribute 클래스에서 정규식을 사용하는 방법을 보여준다.
▶ Movie.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace TestProject.Models { /// <summary> /// 영화 /// </summary> public class Movie { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public int ID { get; set; } #endregion #region 제목 - Title /// <summary> /// 제목 /// </summary> [Required] [StringLength(60, MinimumLength = 3)] public string Title { get; set; } #endregion #region 릴리즈 일자 - ReleaseDate /// <summary> /// 릴리즈 일자 /// </summary> [DataType(DataType.Date)] [Display(Name = "Release Date")] public DateTime ReleaseDate { get; set; } #endregion #region 장르 - Genre /// <summary> /// 장르 /// </summary> [Required] [StringLength(30)] [RegularExpression(@"^[A-Z]+[a-zA-Z]*$")] public string Genre { get; set; } #endregion #region 가격 - Price /// <summary> /// 가격 /// </summary> [DataType(DataType.Currency)] [Column(TypeName = "decimal(18, 2)")] [Range(1, 100)] public decimal Price { get; set; } #endregion #region 등급 - Rating /// <summary> /// 등급 /// </summary> [Required] [StringLength(5)] [RegularExpression(@"^[A-Z]+[a-zA-Z0-9""'\s-]*$")] public string Rating { get; set; } #endregion } } |