Validating User Input

Hi Wix Code community,

I’m trying to use this condition into my .onCustomValidation

if( !value.endsWith(“@wix1.com” || “@wix2.com”))

And also i already tried with

if( !value.endsWith(“@wix1.com”) || !value.endsWith (“@wix2.com”))

But it does’n work, any advice is GREATLY appreciated!

--------------------------------- CODE -----------------------------------------
export function input1_keyPress(event) {
$w(‘#text8’).hide();
}

$w.onReady( function () {
$w(“#input1”).onCustomValidation( (value, reject) => {
if (!value.endsWith(“@wix1.com”) || !value.endsWith (“@wix2.com”) ) {
reject(“E-Mail is invalid”);
$w(‘#text8’).show();

} else {
$w(‘#text8’).hide();

}
});
});

Hello

What is the exact condition you want?

If you want to allow only user with @wix1.com and @wix2.com to be valid the following should work:

 
$w('#input1').onCustomValidation((value, reject) => {
  
 if (value.endsWith("@wix1.com") || value.endsWith("@wix2.com")) {
            $w('#text8').hide();
        } else {
        reject("E-Mail is invalid");
         $w('#text8').show();
        }
    })

Best
Massa

Thank you very much! It works perfect.
Have a excellent day!

Hello Massa

I have a question. Should this code go into the onReady function?
I would like to understand what happens if we add your code in onChange function. Please share your views on advantages and disadvantages of both approaches.

Thank you.