jwaliszko / ExpressiveAnnotations

Annotation-based conditional validation library.
MIT License
351 stars 123 forks source link

Assert IsNumber renders exception #157

Closed petgus closed 7 years ago

petgus commented 7 years ago

I'm doing this [AssertThat("IsNumber(DrillDiameter)")] public double DrillDiameter { get; set; }

And this is what I get [InvalidOperationException: Parse error on line 1, column 10: ... DrillDiameter) ... ^--- Function 'IsNumber' 1st argument implicit conversion from 'System.Double' to expected 'System.String' failed.] ExpressiveAnnotations.Analysis.Parser.Parse(Type context, String expression)

What am I missing? Using version 2.6.8

jwaliszko commented 7 years ago

Would you mind clarifying what is the point of checking whether double is a number? Answering your question - the IsNumber function accepts only arguments of string type, which is what the exception message implicitly says (take a look at built-in functions specification in the docummentation).

petgus commented 7 years ago

Yes sorry of course, feeling kind of stupid now =)

I was totally stressed out and focused on the client-side validation part of it where i have a <input type="text" (me thinking string...). Forgot about the server-side part that happens after binding to my model.

My problem is that I want to validate this both "3.2" AND "3,2" as valid numbers (the difference being the delimiter ',' '.' ).

I guess I will have to implement a custom validator to solve this. Or use bool IsRegexMatch(string str, string regex) And changing my model property type from double to string

Thank you for your time!