Advertisement
StoyanGrigorov

TagAttribute

Mar 9th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace PhotographersDB
  9. {
  10.     public class TagAttribute : ValidationAttribute
  11.     {
  12.         public override bool IsValid(object value)
  13.         {
  14.             string tagString = (string)value;
  15.  
  16.             if (!tagString.StartsWith("#"))
  17.             {
  18.                 return false;
  19.             }
  20.             if (tagString.Contains(" ") || tagString.Contains("\t"))
  21.             {
  22.                 return false;
  23.             }
  24.             if (tagString.Length > 20)
  25.             {
  26.                 return false;
  27.             }
  28.             return true;
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement