ealush / vest

Vest ✅ Declarative validations framework

Home Page:https://vestjs.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

isNotEmpty on a numeric field

Tommuh opened this issue · comments

I have a numeric field with the "isNotEmpty" rule on it.

This numeric field is required. The value "0" is allowed in my use case (0 kg for example).
Leaving the field empty is not allowed.

My problem is that "isNotEmpty" handles 0 as empty (as stated in the documentation) and triggers the error.

I do not know how to solve this problem, can someone please help me with this?

I think that in your case isNotBlank would work better:

https://vestjs.dev/docs/enforce/enforce_rules#isnotblank

enforce(0).isNotBlank(); // passes

Thank you - that did the trick.