Question

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 ?

Thanks

Was it helpful?

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?

OTHER TIPS

Is it possible to validate text against a mask value ?

Of course it's possible, in that you could write a function to take a string and a mask and check one against another.

So I'm unclear on what you're asking - are you asking if there are functions in the standard .Net libraries to do this? Or asking for an implementation of a mask-validation function? Or something else?

If you're looking for something in the library to help, MaskedTextProvider would probably do it, although it's overkill.

Without regexp you have to write your own validation code, which checks the mask.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top