Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 需要验证配置属性-必须是20位数字_C#_.net_Configuration_App Config - Fatal编程技术网

C# 需要验证配置属性-必须是20位数字

C# 需要验证配置属性-必须是20位数字,c#,.net,configuration,app-config,C#,.net,Configuration,App Config,.NET应用程序的用户必须在应用程序配置文件中提供20位的帐号。我从ConfigurationSection派生类来处理自定义节 [ConfigurationProperty("RECEIVED_ACCOUNT", IsRequired = true)] public string RECEIVED_ACCOUNT { get { return (string)this["RECEIVED_ACCOUNT"]; } set { this["RECEIVED_ACCOUNT"] =

.NET应用程序的用户必须在应用程序配置文件中提供20位的帐号。我从ConfigurationSection派生类来处理自定义节

[ConfigurationProperty("RECEIVED_ACCOUNT", IsRequired = true)]
public string RECEIVED_ACCOUNT
{
    get { return (string)this["RECEIVED_ACCOUNT"]; }
    set { this["RECEIVED_ACCOUNT"] = value; }
}
我可以使用
StringValidator
。它提供MaxLength、MinLength和InvalidCharacters。 但它不允许将允许的字符限制为0-9 我建议使用,并将ValidationExpresison属性设置为

^\d{20}$
这将验证正好20位的数字:

  • ^表示匹配字符串的开头
  • \d表示仅匹配数字
  • {20} 表示正好匹配20个字符(前面指定的数字)
  • $表示匹配字符串的结尾