This is an example of custom regex validation for numbers only that is provided in official doc of Windows Community Toolkit
of UWP here TextBox Regex extensions in toolkit.
<StackPanel Margin="10,0,10,0">
<TextBox Name="PhoneNumberValidator"
extensions:TextBoxRegex.Regex="^\s*\+?\s*([0-9][\s-]*){9,}$"
Header="Text box with Regex extension for phone number, validation occurs on TextChanged"
HeaderTemplate="{StaticResource HeaderTemplate}"
Style="{StaticResource TextBoxRegexStyle}" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="Is Valid: " />
<TextBlock Text="{Binding (extensions:TextBoxRegex.IsValid), ElementName=PhoneNumberValidator, Converter={StaticResource StringFormatConverter}}" />
</StackPanel>
</StackPanel>
It works but if i change the regex and use a custom regex /^(?!\s*$).+/
for NotNullOrEmpty
validation then it doesn't work. mean ext:TextBoxRegex.IsValid
always returns false. Why ?