我想验证文本框以检查输入的值是否为英文,这是我的验证类
using System;
using System.ComponentModel;
using System.Text.RegularExpressions;
using Vytru.Base;
namespace Vytru.Platform.Bridge.Configuration.Manager
{
class MapDevice : IDataErrorInfo
{
public string UserName { get; set; }
public string AgentName { get; set; }
public string SipURI { get; set; }
public string Password { get; set; }
public string FQDN { get; set; }
public string Domain { get; set; }
public SipServerTransportType _TransportType { get; set; }
public PeerType _PeerType { get; set; }
public string PeerURI { get; set; }
#region Implementation of IDataErrorInfo
public string this[string columnName]
{
get
{
string result = null;
if (columnName.Equals("UserName"))
{
// check for null or empty values
if (String.IsNullOrEmpty(UserName))
{
result = "User Name cannot be null or empty";
}
else if (UserName.Length > 50)
{
result = "More than 50 characters";
}
else if (UserName.Length < 3)
{
result = "less than 3 characters";
}
else if (!Regex.IsMatch(UserName, @"\w+"))
{
result = "Entered User Name format is not valid ...only A-Z 0-9";
}
}
else if (columnName.Equals("AgentName"))
{
// check for null or empty values
if (String.IsNullOrEmpty(AgentName))
{
result = "Agent Name cannot be null or empty";
}
else if (AgentName.Length < 3)
{
result = "less than 3 characters";
}
else if (AgentName.Length > 50)
{
result = "More than 50 characters";
}
else if (!Regex.IsMatch(AgentName, @"\w+"))
{
result = "Entered AgentName format is not valid ... only A-Z 0-9";
}
}
else if (columnName.Equals("SipURI"))
{
// check for null or empty values
if (String.IsNullOrEmpty(SipURI))
{
result = "Sip URI cannot be null or empty";
}
else if (SipURI.Length < 3)
{
result = "less than 3 characters";
}
else if (SipURI.Length > 50)
{
result = "More than 50 characters";
}
else if (!Regex.IsMatch(SipURI, @"(s|S)+(i|I)+(p|P)+(:)+\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"))
{
result = "Entered SipURI format is not valid ... ";
}
}
if (columnName.Equals("Password"))
{
// check for null or empty values
if (String.IsNullOrEmpty(Password))
{
result = "Password cannot be null or empty";
}
else if (Password.Length > 50)
{
result = "More than 50 characters";
}
else if (Password.Length < 3)
{
result = "Less than 3 characters";
}
else if (!Regex.IsMatch(Password, @"\w+"))
{
result = "Entered Password is not valid ... only A-Z 0-9 ";
}
}
else if (columnName.Equals("FQDN"))
{
// check for null or empty values
if (String.IsNullOrEmpty(FQDN))
{
result = "FQDN cannot be null or empty";
}
else if (FQDN.Length > 50)
{
result = "More than 50 characters";
}
else if (FQDN.Length < 3)
{
result = "Less than 3 characters";
}
else if (!Regex.IsMatch(FQDN, @"\w+"))
{
result = "Entered FQDN format is not valid ... only A-Z 0-9";
}
}
else if (columnName.Equals("Domain"))
{
// check for null or empty values
if (String.IsNullOrEmpty(Domain))
{
result = "Domain cannot be null or empty";
}
else if (Domain.Length > 50)
{
result = "More than 50 characters";
}
else if (Domain.Length < 2)
{
result = "Less than 3 characters";
}
else if (!Regex.IsMatch(Domain, @"\w+"))
{
result = "Entered Domain format is not valid ... ";
}
}
else if (columnName.Equals("PeerURI"))
{
// check for null or empty values
if (String.IsNullOrEmpty(PeerURI))
{
result = "PeerURI cannot be null or empty";
}
else if (PeerURI.Length > 50)
{
result = "More than 50 characters";
}
else if (PeerURI.Length < 3)
{
result = "Less than 3 characters";
}
else if (!Regex.IsMatch(PeerURI, @"\w+"))
{
result = "Entered PeerURI format is not valid ...";
}
}
return result;
}
}
public string Error
{
get { throw new NotImplementedException(); }
}
#endregion
}
}