onCustomValidation problem

Hi,
I’m having some problem with the custom validation on form input. I want to check if the Email inserted ends with “@domain.test” or “@my.domain.test” and to do so I used onCustomValidation as in the snippet below

$w("#input4").onCustomValidation( (value, reject) => {
        console.log(value)
        if(!value.endsWith("@domain.test") && !value.endsWith("@my.domain.test")) {
          reject("Email must be "@domain.test" or "@my.domain.test")
        }
    })

The code above doesn’t work since the form is submitted even if the mail does not match. Moreover the console log is done only when the page is loaded which is very strange.

Does anyone have any idea what I’m doing wrong?