Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Cannot use Regex in Computed observable #28

Open
momoski opened this issue May 22, 2013 · 0 comments
Open

Cannot use Regex in Computed observable #28

momoski opened this issue May 22, 2013 · 0 comments

Comments

@momoski
Copy link

momoski commented May 22, 2013

I have a computed property in my viewmodel like this:

  [Computed]
  public int PasswordScore
  {
      get
      {
          var strongRegex = new Regex("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$");
          var mediumRegex =
              new Regex("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$");
          //var enoughRegex = new Regex("(?=.{6,}).*");
          if (NewPassword.Length < 1)
              return 0;
          if (NewPassword .Length < 6)
              return 1;
          if (strongRegex.Match(NewPassword).Success)
              return 4;

          return mediumRegex.Match(NewPassword ).Success ? 3: 1;

      }
  }

Also I have in my View the following statement:

@ko.Html.Span(m => m.PasswordScore)

I get the error NotSupportedException. This exception happens in VisitMethodCall(MethodCallExpression m).

The state of the variables when reaching that function is:

?m.Method
{System.Text.RegularExpressions.Match Match(System.String)}
[System.Reflection.RuntimeMethodInfo]: {System.Text.RegularExpressions.Match Match(System.String)}
base {System.Reflection.MethodBase}: {System.Text.RegularExpressions.Match Match(System.String)}
MemberType: Method
ReturnParameter: {System.Text.RegularExpressions.Match }
ReturnType: {Name = "Match" FullName = "System.Text.RegularExpressions.Match"}
ReturnTypeCustomAttributes: {System.Text.RegularExpressions.Match }
?m.Object
{HelloWorldModel.expression}
CanReduce: false
DebugView: "KnockoutMvcDemo.Models.HelloWorldModel.expression"
Expression: null
Member: {System.Text.RegularExpressions.Regex expression}
NodeType: MemberAccess
Type: {Name = "Regex" FullName = "System.Text.RegularExpressions.Regex"}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant