clear code

This commit is contained in:
1415ddfer 2024-03-22 23:06:18 +08:00
parent 5fd102c0dc
commit 85e1cc90ba
2 changed files with 0 additions and 170 deletions

View File

@ -1,3 +0,0 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</ResourceDictionary>

View File

@ -1,167 +0,0 @@
using System.Globalization;
using System.Text.RegularExpressions;
using System.Windows.Controls;
/// <summary>
/// 不能为空验证
/// </summary>
public class NotNullValidationRule : ValidationRule
{
public NotNullValidationRule()
{
ValidatesOnTargetUpdated = true;
}
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
if (string.IsNullOrEmpty(value as string) || string.IsNullOrWhiteSpace(value as string))
{
return new ValidationResult(false, "不能为空!");
}
return ValidationResult.ValidResult;
}
}
/// <summary>
/// 自定义正则表达式验证
/// </summary>
/*
1. ^[0-9]*$
2. n位的数字^\d{n}$
3. n位的数字^\d{n,}$
4. m-n位的数字^\d{m,n}$
5. ^(0|[1-9][0-9]*)$
6. ^([1-9][0-9]*)+(.[0-9]{1,2})?$
7. 1-2^(\-)?\d+(\.\d{1,2})?$
8. ^(\-|\+)?\d+(\.\d+)?$
9. ^[0-9]+(.[0-9]{2})?$
10. 1~3^[0-9]+(.[0-9]{1,3})?$
11. ^[1-9]\d*$ ^([1-9][0-9]*){1,3}$ ^\+?[1-9][0-9]*$
12. ^\-[1-9][]0-9"*$ 或 ^-[1-9]\d*$
13. ^\d+$ ^[1-9]\d*|0$
14. ^-[1-9]\d*|0$ ^((-\d+)|(0+))$
15. ^\d+(\.\d+)?$ ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$
16. ^((-\d+(\.\d+)?)|(0+(\.0+)?))$ ^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$
17. ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ ^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$
18. ^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ ^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$
19. ^(-?\d+)(\.\d+)?$ ^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$
1. ^[\u4e00-\u9fa5]{0,}$
2. ^[A-Za-z0-9]+$ ^[A-Za-z0-9]{4,40}$
3. 3-20^.{3,20}$
4. 26^[A-Za-z]+$
5. 26^[A-Z]+$
6. 26^[a-z]+$
7. 26^[A-Za-z0-9]+$
8. 26线^\w+$ ^\w{3,20}$
9. 线^[\u4E00-\u9FA5A-Za-z0-9_]+$
10. 线^[\u4E00-\u9FA5A-Za-z0-9]+$ ^[\u4E00-\u9FA5A-Za-z0-9]{2,20}$
11. ^%&',;=?$\"等字符:[^%&',;=?$\x22]+ 12 禁止输入含有~的字符:[^~\x22]+
1. Email地址^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
2. [a-zA-Z0-9][-a-zA-Z0-9]{0,62}(/.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+/.?
3. InternetURL[a-zA-z]+://[^\s]* 或 ^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$
4. ^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$
5. ("XXX-XXXXXXX""XXXX-XXXXXXXX""XXX-XXXXXXX""XXX-XXXXXXXX""XXXXXXX""XXXXXXXX)^(\(\d{3,4}-)|\d{3.4}-)?\d{7,8}$
6. (0511-4405222021-87888822)\d{3}-\d{8}|\d{4}-\d{7}
7. (1518)^\d{15}|\d{18}$
8. (x结尾)^([0-9]){7,18}(x|X)?$ ^\d{8,18}|[0-9x]{8,18}|[0-9X]{8,18}?$
9. (5-16线)^[a-zA-Z][a-zA-Z0-9_]{4,15}$
10. (6~18线)^[a-zA-Z]\w{5,17}$
11. (使8-10)^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$
12. ^\d{4}-\d{1,2}-\d{1,2}
13. 12(0109112)^(0?[1-9]|1[0-2])$
14. 31(0109131)^((0?[1-9])|((1|2)[0-9])|30|31)$
15.
16. 1.:"10000.00" "10,000.00", "分" "10000" "10,000"^[1-9][0-9]*$
17. 2.0,,"0",^(0|[1-9][0-9]*)$
18. 3.00.^(0|-?[1-9][0-9]*)$
19. 4.00.0.,.^[0-9]+(.[0-9]+)?$
20. 5.,1,"10.", "10" "10.2" ^[0-9]+(.[0-9]{2})?$
21. 6.,,^[0-9]+(.[0-9]{1,2})?$
22. 7..,^[0-9]{1,3}(,[0-9]{3})*(.[0-9]{1,2})?$
23 8.13, +3,,^([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(.[0-9]{1,2})?$
24. ,"+""*"(,?),,
25. xml文件^([a-zA-Z]+-?)+[a-zA-Z0-9]+\\.[x|X][m|M][l|L]$
26. [\u4e00-\u9fa5]
27. [^\x00-\xff] ((2ASCII字符计1))
28. \n\s*\r ()
29. HTML标记的正则表达式<(\S*?)[^>]*>.*?</\1>|<.*? /> ()
30. ^\s*|\s*$(^\s*)|(\s*$) (())
31. QQ号[1-9][0-9]{4,} (QQ号从10000开始)
32. [1-9]\d{5}(?!\d) (6)
33. IP地址\d+\.\d+\.\d+\.\d+ (IP地址时有用)
34. IP地址((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))
*/
public class CustomRegularValidationRule : ValidationRule
{
public CustomRegularValidationRule()
{
ValidatesOnTargetUpdated = true;
}
public string RegularString { get; set; } // 正则表达式规则
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
string str = value as string;
if (!string.IsNullOrWhiteSpace(str))
{
// 检查输入的字符串是否符合当前正则规范
if (!Regex.IsMatch(str, RegularString))
{
return new ValidationResult(false, "内容格式不正确");
}
}
return ValidationResult.ValidResult;
}
}
/// <summary>
/// 长度限制
/// </summary>
class LengthLimitValidationRule : ValidationRule
{
public LengthLimitValidationRule()
{
ValidatesOnTargetUpdated = true;
}
public double Minimum { get; set; }
public double Maximum { get; set; }
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
if (value == null) return ValidationResult.ValidResult;
double number = value.ToString().Length;
if (number > Maximum || number < Minimum)
{
return new ValidationResult(false, string.Format("值长度限制在 {0} 到 {1}", Minimum, Maximum));
}
return ValidationResult.ValidResult;
}
}
/// <summary>
/// ip规则验证
/// </summary>
public class IPAddressRule : ValidationRule
{
public IPAddressRule()
{
ValidatesOnTargetUpdated = true;
}
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
string IPAddress = value as string;
if (!string.IsNullOrWhiteSpace(IPAddress))
{
string IPAddressFormartRegex = @"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$";
// 检查输入的字符串是否符合IP地址格式
if (!Regex.IsMatch(IPAddress, IPAddressFormartRegex))
{
return new ValidationResult(false, "IP地址格式不正确");
}
}
return ValidationResult.ValidResult;
}
}