Using pattern validation to enable/disable a button

Hello,
I’m trying to finish up our website’s customer registration page, but running into a problem. I’m trying to use validation settings to keep the submit button disabled until all the text fields have been filled out. Here’s the code:

// For full API documentation, including code examples, visit Velo API Reference - Wix.com
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady( function () {
//TODO: write your page related code here…
$w(‘#CustFName’).onChange(FinishEnableDisable)
$w(‘#CustLName’).onChange(FinishEnableDisable)
$w(‘#CustPhone’).onChange(FinishEnableDisable)
$w(‘#CustAdr1’).onChange(FinishEnableDisable)
$w(‘#CustCity’).onChange(FinishEnableDisable)
$w(‘#CustState’).onChange(FinishEnableDisable)
$w(‘#CustZip’).onChange(FinishEnableDisable)
});

function FinishEnableDisable() {
if ($w(‘#CustFName’).valid && $w(‘#CustLName’).valid && $w(‘#CustPhone’).valid && $w(‘#CustAdr1’).valid && $w(‘#CustCity’).valid && $w(‘#CustState’).value <=52 && $w(‘#CustZip’).valid) {
$w(‘#Submit’).enable()
} else {
$w(‘#Submit’).disable()
}
}

Also here are screen shots of the pattern validation settings I have defined. CustState is a dropdown menu with each state corresponding to a numerical value, as well as an option for Territories/Outlying Islands (51) Non-Us (52) and the placeholder “Select a state” (53). I did it this way so if the value is equal or less than 52, it’s valid and keeping it on the placeholder is invalid.


CustFName, CustLName, CustAdr1, and CustCity use this pattern validation (CusAdr1 has a character limit of 30)


CustPhone Pattern Validation


CustZip Pattern Validation

You need to make sure your regexp has the correct syntax. At the moment you are trying to match numbers. \d is:
Matches any digit (Arabic numeral).

You probably need to use [\w\s]{<=20} for your text strings.

Read the regexp link above or go to w3schools and play in their try it space. :wink:

Thank you very much for your reply! I am honestly new to wix code and java itself, and I’m figuring it out well enough, but of course there’s intricacies I’m not aware of.

@sophiagibson No problem. By the way this is Javascript, not Java. There is a big difference between the two languages. It’s important you make sure you know which one you are using ;-).