Optional field with validation

Is it possible to have an optional field and apply validation to the field only when the user has entered something into the field?

image

Solved my own problem
image