Call a method when input is invalid

I have a form.
I want to show a Toast when the inputs of the form are invalid and for this I create the Toast in a method in my codes.
So how can I call the method when a input is invalid?