Search code examples
c#masking

Validate text against mask value in C#


I need to validate a certain property to one of my classes. When I set the property, the class should validate the input and if incorrect, set the object to an invalid state.

Question : The property value must be in a certain mask/format eg. &&&&-&&&&-&&&&. I cannot use regular expressions. Is it possible to validate text against a mask value?


Solution

  • Regular expressions are often over-used, but this is a pretty good example of when a regex is ideal... so: why can't you use them here?