Search code examples
regexvisual-studio-lightswitchlightswitch-2013

Validation Error in Lightswitch with RegEx


I have a property that is NIF, and is like SSN but in Spain and the format can be:

A0000000A  
00000000A  
A00000000

Where A stands for Alphanumeric and 0 for Digits. In any case it must be 9 characters.

Using Visual Studio 2013 LightSwitch I try to validate it using RegEx.
The regular expression I wrote for this case is

^\b\w\d{7}\w\b$

and I have tested in several webs, and so far, the RegEx works.

But when I run the app put a valid data it doesn't work and the validation error appears on screen.
Here is the validation code:

Private Sub NIF_Validate(results As EntityValidationResultsBuilder)

    Dim pattern As String = "^\b\w\d{7}\w\b$"

    If (NIF IsNot Nothing) AndAlso (Not Regex.IsMatch(pattern, NIF)) Then
            results.AddPropertyError("Check NIF")
    End If

End Sub

Solution

  • Finally, after many hours reviewing the code I found the error. Its in Regex.IsMatch where the first parameter must be the text and the second one the pattern.

    Regex.IsMatch(input As String, pattern As String)
    

    Thanks for the answers. And sorry for the silly mistake.