1

The user of my .NET application must provide 20-digit account number in the application configuration file. I am derived class from ConfigurationSection to work with custom sections.

[ConfigurationProperty("RECEIVED_ACCOUNT", IsRequired = true)]
public string RECEIVED_ACCOUNT
{
    get { return (string)this["RECEIVED_ACCOUNT"]; }
    set { this["RECEIVED_ACCOUNT"] = value; }
}

I could use StringValidator. It provides MaxLength, MinLength and InvalidCharacters. But it does not allow to limit allowed characters to 0-9 w

Captain Comic
  • 15,744
  • 43
  • 110
  • 148

1 Answers1

3

I would suggest using a Regular Expression Validator and setting the ValidationExpresison property to be

^\d{20}$

This will validate a number of exactly 20 digits:

  • ^ means match the start of the string
  • \d means match digits only
  • {20} means match exactly 20 characters (of the digit specified previously)
  • $ means match the end of the string
Rob Levine
  • 40,328
  • 13
  • 85
  • 111