Regex expression throws error although it is valid


Hi

I am trying to use the SfMaskedEdit control inside a SfTextInputLayout control.

I want to validate if the entered value is a valid date. I found this Regex mask that properly does validate the date:

^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[13-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$

You can test it here: RegEx Date test

In XAML I defined
                    <sf:SfTextInputLayout
                        x:Name="DateOfBirth"
                        Grid.Column="2"
                        Hint="Overlijdensdatum"
                        ToolTip="bijv 23-05-2020">
                        
                        <sf:SfMaskedEdit
                            Foreground="{Binding ElementName=DateOfBirth, Path=Foreground, Mode=TwoWay}"
                            ValidationMode="KeyPress"
                            MaskType="RegEx"
                            Mask="^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[13-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$"
                            Value="{Binding Path=DateOfBirth, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                    </sf:SfTextInputLayout>

I am getting this error. Would you have any idea what is causing this or how to fix this?

Kind regards,

Niels van Strien

System.Text.RegularExpressions.RegexParseException
  HResult=0x80070057
  Message=Invalid pattern '?:(?:31(\/' at offset 1. Quantifier {x,y} following nothing.
  Source=System.Text.RegularExpressions
  StackTrace:
   at System.Text.RegularExpressions.RegexParser.ScanRegex()
   at System.Text.RegularExpressions.RegexParser.Parse(String pattern, RegexOptions options, CultureInfo culture)
   at System.Text.RegularExpressions.Regex.Init(String pattern, RegexOptions options, TimeSpan matchTimeout, CultureInfo culture)
   at System.Text.RegularExpressions.Regex..ctor(String pattern, CultureInfo culture)
   at System.Text.RegularExpressions.RegexCache.GetOrAdd(String pattern)
   at System.Text.RegularExpressions.Regex.IsMatch(String input, String pattern)
   at Syncfusion.Windows.Controls.Input.SfMaskedEdit.IsORExpressionMatch(Int32 caretIndex, String typedText, Char& outputChar, MaskProperties mask)
   at Syncfusion.Windows.Controls.Input.SfMaskedEdit.MatchWithMask(Char typedChar, Boolean matchLiteral, Boolean isKeyPress)
   at Syncfusion.Windows.Controls.Input.SfMaskedEdit.MatchWithMask(Char typedChar, Boolean isValuematching)
   at Syncfusion.Windows.Controls.Input.SfMaskedEdit.OnPreviewKeyDown(KeyEventArgs e)
   at System.Windows.UIElement.OnPreviewKeyDownThunk(Object sender, KeyEventArgs e)
   at System.Windows.Input.KeyEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawKeyboardActions actions, Int32 scanCode, Boolean isExtendedKey, Boolean isSystemKey, Int32 virtualKey)
   at System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled)
   at System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers)
   at System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(MSG& msg, Boolean& handled)
   at System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run()
   at EPD3.App.Main()

  This exception was originally thrown at this call stack:
    [External Code]

1 Reply

SG Sangeetha Ganesan Syncfusion Team May 24, 2021 11:36 AM UTC

Hi NM van Strien,     
     
Thank you for contacting Syncfusion support.     
     
We have checked your query  “Regex expression throws error although it is valid” from our end. As of now, we don’t have support for group regular expression in SfMaskedEdit control and we have logged a feature request for the same. We will implement this feature in any of our upcoming releases. Thank you for requesting this feature and helping us define it. We are always trying to make our products better and feature requests like yours are a key part of our product growth efforts. You can also communicate with us regarding the open features any time using our Feature Report page.      
     
We will prioritize the features every release based on the demands and we do not have an immediate plan to implement this feature since we committed with already planned work. So, this feature will be available in any of our upcoming releases. Please upvote this features to make this our priority. While this feature itself is important we will prioritize the features every release, based on the user demands. So, this feature will be available in any of our upcoming releases     
      
    
If you have any more specification/suggestions to the feature request, you can add it as a comment in the portal and cast your vote to make it count.     
     
Regards,   
Sangeetha G 


Loader.
Up arrow icon