|
using System;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Codebasement.DomainDrivenDesign.Basement.Utilities;
namespace Codebasement.DomainDrivenDesign.Model.Validators
{
internal static class PropertyValidators
{
private const string caption = "Codebasement";
internal static bool ValidateDateTime(string value)
{
try
{
DateTime.Parse(value);
}
catch
{
return false;
}
return true;
}
internal static object ValidateEnum(Type enumeration, string val, object deflt)
{
if (val != null && Enum.IsDefined(enumeration, val))
return Enum.Parse(enumeration, val);
return deflt;
}
internal static bool ValidateStringLength(string value, int min, int max)
{
if (value.Length < min ||
value.Length > max)
{
MessageBox.Show(String.Format("Length must be between {0} and {1}.",min,max),
caption,MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
return true;
}
internal static bool ValidateIPAddress(string value)
{
if (String.IsNullOrEmpty(value))
return true;
Regex regex = new Regex(RegexExpressions.IPAddressFormat);
if (!regex.Match(value).Success)
{
MessageBox.Show("Not a valid IP address.",
caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
return true;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.