ASP.NET MVC ã§å©ç¨ã§ããå ¥åæ¤è¨¼ã¯æã£ãããå¤ãããã¾ãããæ£è¦è¡¨ç¾ã§æå®ã§ããæ¤è¨¼å±æ§ãç¨æããã¦ãã¾ããããã使ãããã§ãããã¡ã¼ã«ã¢ãã¬ã¹ãªã©ã®æ¤è¨¼ãè¡ãããã«ã¯ãèªåã§æ£è¦è¡¨ç¾ãæ¸ããªã©ãã¦æå®ããå¿ è¦ãããã¾ãã
ç§ã¯æ®æ®µ PHP ã§æ¥åã¢ããªã±ã¼ã·ã§ã³ãæ¸ãã¦ãã®ã§ãããå ¥åæ¤è¨¼ã¯é常ã«éè¦ã«ãªãã¾ãã®ã§ã¯ã©ã¹ã«ã¾ã¨ãã¦åå©ç¨å¯è½ã«ãã¦ãã¾ãããã MVC ã§éçºããã¨ãããé常ã«é¢åãªãã¨ã«ãªãããã ã£ãã®ã§ãç°¡åã«ã¾ã¨ãã¦ããããã¨æãã¾ãã
注æï¼ããã®æ£è¦è¡¨ç¾ã¯ä¸ã¤ã®ä¾ã¨æãã¦ãã ãããåºæ¬çã«èª°ã§ãæãã¤ããããªç°¡åãªæ£è¦è¡¨ç¾ãªã®ã§ã
åè§è±å
[RegularExpression(@"[a-zA-Z]+", ErrorMessage = "åè§è±åã®ã¿å ¥åã§ãã¾ãã")] public string Alphabet { get; set; }
åè§æ°å
[RegularExpression(@"[0-9]+", ErrorMessage = "åè§æ°åã®ã¿å ¥åã§ãã¾ãã")] public string Number { get; set; }
åè§è¨å·
[RegularExpression(@"[ -/:-@\[-\`\{-\~]+", ErrorMessage = "åè§è¨å·ã®ã¿å ¥åã§ãã¾ãã")] public string Symbol { get; set; }
åè§è±æ°å
[RegularExpression(@"[a-zA-Z0-9]+", ErrorMessage = "åè§è±æ°åã®ã¿å ¥åã§ãã¾ãã")] public string AlphaNumber { get; set; }
åè§è±æ°åè¨å·
[RegularExpression(@"[a-zA-Z0-9 -/:-@\[-\`\{-\~]+", ErrorMessage = "åè§è±æ°åè¨å·ã®ã¿å ¥åã§ãã¾ãã")] public string AlphaNumberSymbol { get; set; }
åè§ã«ã¿ã«ã
[RegularExpression(@"[。-ï¾+]+", ErrorMessage = "åè§ã«ã¿ã«ãã®ã¿å ¥åã§ãã¾ãã")] public string HalfKatakana { get; set; }
å ¨è§ã«ã¿ã«ã
[RegularExpression(@"[ã¡-ã¶]+", ErrorMessage = "å ¨è§ã«ã¿ã«ãã®ã¿å ¥åã§ãã¾ãã")] public string FullKatakana { get; set; }
éµä¾¿çªå·
[RegularExpression(@"\d{3}-\d{4}", ErrorMessage = "æ£ããéµä¾¿çªå·ã§ã¯ããã¾ããã")] public string Zip { get; set; }
åå¨ããéµä¾¿çªå·ãã©ããã®ãã§ãã¯ã¾ã§è¡ãããå ´å㯠RemoteAttribute ã¨éµä¾¿çªå·ãã¼ã¿ãã¼ã¹ãç¨æãã¦å®è£ ããã¨ããã¨æãã¾ãã
[Remote("Check", "Zip", ErrorMessage = "åå¨ããªãéµä¾¿çªå·ã§ãã")] public string Zip { get; set; }
é»è©±çªå·
[RegularExpression(@"\d{2,4}-\d{1,4}-\d{4}", ErrorMessage = "æ£ããé»è©±çªå·ã§ã¯ããã¾ããã")] public string Tel { get; set; }
ã¡ã¼ã«ã¢ãã¬ã¹
[RegularExpression(@"[\w!#$%&'*+/=?^_@{}\\|~-]+(\.[\w!#$%&'*+/=?^_{}\\|~-]+)*@([\w][\w-]*\.)+[\w][\w-]*", ErrorMessage = "æ£ããã¡ã¼ã«ã¢ãã¬ã¹ã§ã¯ããã¾ããã")] public string Email { get; set; }
MvcFutures ã® EmailAddressAttribute ã使ãã¨ã·ã³ãã«ã«ãã¤æ£ç¢ºãªãã§ãã¯ã§æ¸ãã¾ãã
[EmailAddress(ErrorMessage = "æ£ããã¡ã¼ã«ã¢ãã¬ã¹ã§ã¯ããã¾ããã")] public string Email { get; set; }
URL
[RegularExpression(@"https?:\/\/[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]+", ErrorMessage = "æ£ãã URL ã§ã¯ããã¾ããã")] public string Url { get; set; }
MvcFutures ã® UrlAttribute ã使ãã¨ã·ã³ãã«ã«æ¸ãã¾ãã
[Url(ErrorMessage = "æ£ãã URL ã§ã¯ããã¾ããã")] public string Url { get; set; }