I have an input field and a button. The button should be enabled on the following simple scenarios:
- Input length is equal to 10, or
- Input length is greater than 15 (should be disabled for 11 to 14).
I tried !str.length = 10 || !str.length >= 15
, but these conditions fail, as there is a conflict between both cases. I know I can check whether the length is not equal to 11, 12, 13, or 14, but that doesn't look good. Any better solution will be appreciated.
You used the single equal sign
=
in your first condition, which is used for setting variables, not checking what they are. It needs to either be==
or===
, and in this case,===
is preferred, since==
is used to check between two of different types (e.g. string, integer).Should be:
Edit: It seems necessary to state that, despite the OP saying it should be enabled if equal to 10 or "greater than 15," the OP clearly means equal to or greater than 15, because the OP indicates three times that this is what they mean by saying "(should be disabled for 11 to 14)," putting "
>= 15
," and again saying, "not equal to 11, 12, 13, or 14."