match regex in MaskedTextBox with empty string

Editors for WPF Forum

Posted 7 years ago by Josh Dice
Version: 11.2.0552
Avatar

Hi,

I'm using a MaskedTextBox to validate an IP Address and would also like it to match when the MaskedTextBox is empty.

Here is my XAML:

<Editors:MaskedTextBox x:Name="ipAddressTextBox"
         Grid.Row="1"
         Width="100"
         Height="24"
         Mask="^(\s*|[0-9]{0,3}[.][0-9]{0,3}[.][0-9]{0,3}[.][0-9]{0,3})$"
         MaskType="Regex"
         Text="{Binding Path=IpAddressComparableValue,
             RelativeSource={RelativeSource TemplatedParent},
             UpdateSourceTrigger=LostFocus,
             ValidatesOnDataErrors=True,
             Converter={StaticResource ipAddressComparableTextConverter}}"
         ToolTip="{x:Static Properties:Resources.IpAddressTextBoxToolTip}" />

 

The regex that I'm using should work but the behavior in the MaskedTextBox isn't what I hoped for.  Is there a way to match the IP Address regex and allow the text box to be empty also?

 

Thanks,

Josh

Comments (1)

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Josh,

What if instead of the "\s*|" portion, you just put a ? after the parenthesis to make it optional?

[Modified 7 years ago]


Actipro Software Support

The latest build of this product (v2019.1 build 0682) was released 26 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.