Shaun Summers
Posts: 0
Joined: Thu Jul 25, 2013 3:49 pm

Valid email address code not working.

Hi,

I've used the code from tutorial https://devcenter.appery.io/tutorials... to validate the registration fields. It all works fine except for checking that the email address is a valid email format.

if ($.trim(Appery("loginInput").val()) !== "") {
if (Appery("passwordInput").val() == Appery("confirmPasswordInput").val()) {
if ($.trim(Appery("emailInput").val()) !== "") {
if (!document.getElementsByName("emailInput")[0].checkValidity || document.getElementsByName("emailInput")[0].checkValidity()) {register.execute({});
} else {
alert("Please enter a valid email");
}
} else {
alert("Please specify your email");
}
} else {
alert("Passwords don't match!");
}
} else {
alert("Please enter your login");
}

_________________

Any ideas on where I've gone wrong. I've doubled checked it against the original and all my field names are correct.

Regards, Shaun.

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Valid email address code not working.

Hello Shaun,

Please try this code to validate email while we're testing the one from the tutorial
precodefunction validateEmail(email) {
var re = /^([\w-]+(?:\.[\w-]+))@((?:[\w-]+\.)\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
return re.test(email);
}/code/pre

Shaun Summers
Posts: 0
Joined: Thu Jul 25, 2013 3:49 pm

Valid email address code not working.

Thanks for the answer. I'm afraid I don't really understand where to include the code that you've given me in the original code that I posted (I've just been following the tutorial...)

Shaun.

Shaun Summers
Posts: 0
Joined: Thu Jul 25, 2013 3:49 pm

Valid email address code not working.

I got another work around to work. I've posted it here in case it is useful for somebody else:

if ($.trim(Appery("Country_Select").val()) !== "Not_selected") {
if ($.trim(Appery("loginInput").val()) !== "") {
if (Appery("passwordInput").val() == Appery("confirmPasswordInput").val()) {
if ($.trim(Appery("emailInput").val()) !== "") {
if( /(.+)@(.+){2,}\.(.+){2,}/.test((Appery("emailInput").val()))) {register.execute({});
} else {
alert("Please enter a valid email");
}
} else {
alert("Please specify your email");
}
} else {
alert("Passwords don't match!");
}
} else {
alert("Please enter your login");
}
} else {
alert("Please enter your country");
}

Regards, Shaun

Gurinder Mann
Posts: 0
Joined: Tue Jul 28, 2015 4:54 pm

Valid email address code not working.

function validateEmail(email)
{
var re = /^([\w-]+(?:\.[\w-]+))@((?:[\w-]+\.)\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
return re.test(email);
}
var email = Apperyio('txt_mobiletextinput_4').val();

var errorMsg = "";

if ($.trim(email) === "")
{
errorMsg = errorMsg + "Email cannot be blank \n";
}

if (errorMsg === "")
{
restservice2.execute({});
}
else
{
alert("Please fix the following error: \n" + errorMsg);
}

---------------------------------------------------------------------------------------------------------

This is the code I am using I want to validate the email and display a error message if the email is not valid. how do I fix the code to do that??

Return to “Issues”