At the front of the site I have a lightbox popup which allows the user to find out if their postcode is covered by the delivery service. I have the postcodes in various formats in the database however the result won’t be found unless in all uppercase.
I put a Regex validation code on the text input field but that just highlights the box if it it isn’t in the correct format as opposed to changing it automatically.
I’m relatively new to all this so in lay terms would be really helpful.
Thank you!
/// THIS IS THE CODE FROM THE LIGHTBOX JUST IN CASE I’VE MADE AN ERROR HERE TOO.
import wixUsers from ‘wix-users’ ;
import {local} from ‘wix-storage’ ;
import wixData from ‘wix-data’ ;
import wixLocation from ‘wix-location’ ;
import wixWindow from ‘wix-window’ ;
$w.onReady( function () {
$w( ‘#button2’ ).onClick((event, $w) => {
onClick(event, $w);
})
})
export function onClick(event, $w){
let postcode = $w( ‘#input1’ ).value;
//Blank field exception
if (postcode === “” ){
$w( ‘#error’ ).show();
return ;
}
wixData.query( “Postal” ).eq( “title” ,postcode).find().then((results) =>{
let resultCount = results.totalCount;
//Check that user with the postal code exists
if (resultCount === 0 ){
wixWindow.openLightbox( “Outside delivery zone” );
}
if (resultCount > 0 ){
wixWindow.openLightbox( “Delivery within 10km” );
}
}, (err) => {
console.log(err);
})
}
The Regex code I was using is:
^(A[BL]|B[ABDFHLNRSTX]?|C[ABFHMORTVW]|D[ADEGHLNTY]|E[CHNX]?|F[KY]|G[LUY]?|H[ADGPRSUX]|I[GMPV]|JE|K[ATWY]|L[ADELNSU]?|M[EKL]?|N[EGNPRW]?|O[LX]|P[AEHLOR]|R[GHM]|S[AEGKLMNOPRSTWY]?|T[ADFNQRSW]|UB|W[ACDFNRSV]?|YO|ZE)(\d[\dA-Z]?) ?(\d)([A-Z]{2})$
Thanks in advance