using System.Data.SqlTypes; using Microsoft.SqlServer.Server; using System.Text.RegularExpressions; namespace Neo.Afx.Validation { /// /// The formatter. /// public class RsaCompanyRegNumberValidation { /// /// Does check digit validation on an RSA Company Registration Number /// /// The Company Registration Number. /// True/False [SqlFunction( IsDeterministic = true, IsPrecise = true, DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read )] public static SqlBoolean IsValidRsaCompanyRegNum(SqlString companyRegNumber) { var isValid = false; var companyRegNumberToCheck = companyRegNumber.Value; if (string.IsNullOrEmpty(companyRegNumberToCheck)) { return new SqlBoolean(isValid); } Regex rgx = new Regex(@"^\d{4}\/\d{6}\/\d{2}$"); if (rgx.IsMatch(companyRegNumberToCheck)) { isValid = true; } return new SqlBoolean(isValid); } } }