E-mail validation

Hi, does anyone know what validation code I need to validate an email?

Hey,
You can find information about validating user’s input here:

Have a good day,
Tal.

Hi, I checked out the articles, but I didn’t find the validation code for an email. Basically, I need to check if it contains ‘@’ and ‘.’.

Also, how would I go about stopping the form submission if the validation fails?

Hi there,

I f you are using a text input you can set the type to be email.

So e-mail type automatically does an internal validation?

Indeed.

Thank you!!! :slight_smile: :slight_smile: :slight_smile:

Hi, the problem with using the “Email” type input setting is that it also accept “w@s” as an email. Is this a bug?

Yes there is a bug with Wix’s text input email validation, raised it a long time ago. Better use regex to validate the user’s entry

var email_regex = /^(([^<>()\[\]\\.,;:\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(email_regex.test($w("#input1").value)) {
    console.log('Valid');
} else {
    console.log('Invalid');
}
3 Likes

Thank you!