Hi Wix Code community,
I’m trying to add an a conditional to check if in the input field the user wrote an a lowercase letter and show a message at the user with the mistake to can change it.
This is the code that i have till the moment but i want add a “Else if” with the new condition.
$w.onReady( function () {
$w(“#input1”).onCustomValidation( (value, reject) => {
if ((value.length > 1) & (value.length < 12) ) {
reject(“BMX is invalid”);
$w(‘#text8’).show();
} else if (value === “BMXDOI007985”) {
reject(“BMX is invalid”);
$w(‘#text9’).show();
}
else {
$w(‘#text8’).hide();
$w(‘#text9’).hide();
}
});
});
Any advice is GREATLY appreciated!
Does the following work for you:
else if (/[a-z]/.test(value)) {
reject("Lowercase letters are not allowed in BMX.");
$w('#text9').show();
}
?
Thank you very much! It works perfect.
Have a excellent day!
You as well.
BTW, I recommend that you replace generic names like #input1 , #text8 , and #text9 with meaningful/mnemonic names; it makes your code easier to maintain (read/understand/debug).
Hi @abergquist
Can you help me again? 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!
Hi, Fernando.
I believe the following is what you want:
if ( !(value.endsWith("@wix1.com") || value.endsWith ("@wix2.com") )
To understand the above, read it from the inside out (as in "First determine if the value ends with “@wix1.com” or “@wix2.com”; then negate that logical/boolean condition and use that negated condition as the expression for the if statement).