That looks like it will work.
And if this is the only place you will ever need to do this it should be OK enough.
But instead of
if (this) {
output stuff
}
if (that) {
output stuff
}
If “output stuff” is exactly the same, I would do
if ((this) || (that)) {
output stuff
}
instead. A matter of easier to read conditionals vs. less duplication