refactor: 将Framework库和RT、UI放在同一个解决方案中。
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Aitex.Core.UI.ValidationRules
|
||||
{
|
||||
/// <summary>
|
||||
/// Validate email address.
|
||||
/// </summary>
|
||||
public class ValidateEmailAddress : ValidationRule
|
||||
{
|
||||
/// <summary>
|
||||
/// Implement the rule that validates phone number.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="cultureInfo"></param>
|
||||
/// <returns></returns>
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
|
||||
{
|
||||
var emailAddress = (string)value;
|
||||
|
||||
var pattern = @"\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b";
|
||||
|
||||
var match = Regex.Match(emailAddress, pattern, RegexOptions.IgnoreCase);
|
||||
|
||||
if (match.Value.Equals(emailAddress))
|
||||
{
|
||||
return new ValidationResult(true, null);
|
||||
}
|
||||
|
||||
return new ValidationResult(false, "Invalid email address.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Aitex.Core.UI.ValidationRules
|
||||
{
|
||||
/// <summary>
|
||||
/// Validate phone number.
|
||||
/// </summary>
|
||||
public class ValidatePhoneNumber : ValidationRule
|
||||
{
|
||||
/// <summary>
|
||||
/// Implement the rule that validates phone number.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="cultureInfo"></param>
|
||||
/// <returns></returns>
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
|
||||
{
|
||||
var phoneNumber = (string)value;
|
||||
|
||||
var pattern = @"\d{8,13}";
|
||||
|
||||
var match = Regex.Match(phoneNumber, pattern);
|
||||
|
||||
if (match.Value.Equals(phoneNumber))
|
||||
{
|
||||
return new ValidationResult(true, null);
|
||||
}
|
||||
|
||||
return new ValidationResult(false, "Invalid phone number. Phone number must be 8-13 digits.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Aitex.Core.UI.ValidationRules
|
||||
{
|
||||
/// <summary>
|
||||
/// Validate user name
|
||||
/// </summary>
|
||||
public class ValidateUserName : ValidationRule
|
||||
{
|
||||
/// <summary>
|
||||
/// Implement the rule that validates user name.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="cultureInfo"></param>
|
||||
/// <returns></returns>
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
|
||||
{
|
||||
var userName = (string)value;
|
||||
|
||||
// Unicode编码中的汉字范围是/^[\u2E80-\u9FFF]+$/
|
||||
var pattern = @"[a-zA-Z_\u2E80-\u9FFF]{1}[\w\u2E80-\u9FFF]{0,7}";
|
||||
|
||||
var match = Regex.Match(userName, pattern);
|
||||
|
||||
if (match.Value.Equals(userName))
|
||||
{
|
||||
return new ValidationResult(true, null);
|
||||
}
|
||||
|
||||
return new ValidationResult(false, "Invalid user name");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user