1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
using System; using System.ComponentModel.DataAnnotations; namespace DevHive.Web.Attributes { public class OnlyAlphanumerics : ValidationAttribute { public override bool IsValid(object value) { var stringValue = (string)value; foreach (char ch in stringValue) { if (!Char.IsLetterOrDigit(ch)) return false; } return true; } } }