Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import wixData from 'wix-data';
let options = {
"suppressAuth": true,
"suppressHooks": true
};
export function validateEmail(email) {
var emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if(emailRegex.test(email)){
// proceed with insert into database
dataInsert(email);
return {status: 200};
}else{
return {
status: 400,
error: {
message: 'Email is invalid'
}
};
}
}
const dataInsert = (email) => {
let toInsert = {
title: email
};
wixData.insert('subscribers', toInsert, options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment