views:

43

answers:

2

Hi,

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

+1  A: 

You could use Regular Expressions, maybe this will help you.

Jottiza
+3  A: 

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