How to validate email address using custom validation?

Can someone help with validating the input of whether it is a valid email address using custom validation code?

Please see the code below.

Not interested for the regex you can add as pattern validation in the input settings.
I am looking for code thanks.

$w("#email").onCustomValidation( (value, reject) => {

let isValid = $w("#email").valid;

if ((($w('#email').value) !== isValid ) ||
(($w('#email').value) !== isValid )){

reject("Invalid value.");
$w("#ex3").show();
$w("#tick3").hide();
}
else {
$w("#tick3").show();
$w("#ex3").hide();

Hello, Gio.

It depends on what exactly you are trying to achieve. If you would like to display an error to the user logging in if an incorrect email is entered, check out this related forum post.

If you want to validate email before adding it to a collection, please refer to the article below:
Corvid: About Validating User Input with Code

Good luck!

Thanks Anastasia,

As per code above I am trying to use custom validation on a custom registration form.

I am trying validate as per user input the email address to have a proper format such as “example@example.com” Unfortunately I am unable to do that via code.

Ultimately what I am trying to achieve is to show error, that is via error image on every occasion a user is trying to register using an invalid email address such as lets say “example@example” - in essence violating the email address format.

The text input is set for email but what I am trying is to show both error and correctness every time a user adjusts the input text for email.

thanks again for any insight.

Hi, I’m not sure whether you are still working on this, but I would like to give you a small hint on this.

Since you are trying to validate the format of the email address user input, you can follow below steps
select your textbox, select settings, from “Type” select “Email”

Hi Anastasia

I am getting an error with your it says onCustomValidation is not a function do you have the function code for this $w call it normally looks at an smtp server and are any wix import modules required if so which ones please

Please add your own issue into a new post instead of bumping up an old post. Explain what you are trying to do, what works, and what doesn’t. Also, add any code in a code block as stated in the Forum Guidelines .