■ ValidationRule 클래스를 사용해 현재 날짜보다 미래 날짜 여부를 검증하는 방법을 보여준다.
▶ 예제 코드 (C#)
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 |
using System; using System.Globalization; using System.Windows.Controls; /// <summary> /// 미래 날짜 규칙 /// </summary> public class FutureDateRule : ValidationRule { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 검증하기 - Validate(value, cultureInfo) /// <summary> /// 검증하기 /// </summary> /// <param name="value">값</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>검증 결과</returns> public override ValidationResult Validate(object value, CultureInfo cultureInfo) { DateTime date; try { date = DateTime.Parse(value.ToString()); } catch(FormatException) { return new ValidationResult(false, "Value is not a valid date. Please enter a valid date"); } if(DateTime.Now.Date > date) { return new ValidationResult(false, "Value is not a future date. Please enter a date in the future."); } return ValidationResult.ValidResult; } #endregion } |