Validating User Input

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”);
} else if (value === “BMXDOI007985”) {
reject(“BMX is invalid”);

else {

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.");



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).

1 Like

Hi @abergquist
Can you help me again? I’m trying to use this condition into my .onCustomValidation

if( !value.endsWith(“” || “”))

And also i already tried with

if( !value.endsWith(“”) || !value.endsWith (“”))

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

Hi, Fernando.

I believe the following is what you want:

if ( !(value.endsWith("") || value.endsWith ("") )

To understand the above, read it from the inside out (as in "First determine if the value ends with “” or “”; then negate that logical/boolean condition and use that negated condition as the expression for the if statement).