I have many TextBox's on my xaml where I've implemented Regex validation (from
How to Define TextBox Resctrictions). In my view, this takes the form of:
<TextBox
h:ColorMaskingTextBoxBehavior.Mask="^(?:\d{5})(?:-\d{4})?$"
Text="{Binding ZipCode}"
Height="21" HorizontalAlignment="Left" Margin="152,207,0,0" VerticalAlignment="Top" Width="96"
/>
I do not wish to restrict the movement of the user so currently validation simply changes the colors of the textbox; red being an error was discovered.
After all input is gathered, the user is to click on Save to save the window. The regex codes can be involved and it seems wrong to copy them from the xaml to the viewmodel where Save is executed.
How can the attached behavior flag the textbox as invalid so that the viewmodel need only check the invalid flag before saving the window? My first thought is to bind the Tag dependency property on the textbox but I wonder if there is a better way?
Any ideas are appreciated.
TIA