Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
28
rated 0 times [  34] [ 6]  / answers: 1 / hits: 19960  / 13 Years ago, thu, june 30, 2011, 12:00:00

I have a textbox where the user is required to insert a valid email address.



When the user submits a valid email address a loading graphic appears while the data is posted back.



The code below works fine for showing the loading graphic but it does not check that the email address is valid first. Can anyone help out?



$('#btnEmail1Submit').live (click, function() {
$('<div class=submitBg></div>').appendTo(.emailEditContainer);
$('<div class=submitLoadingCont><img class=submitLoading src=images/mypreferences/loading.gif width=50 height=50 /></div>').appendTo(.emailEditContainer);
});


I am thinking that I need to put an if statement around the function that is run on click - so something like:



$('#btnEmail1Submit').live (click, function() {
if(emailvalid == true) {
$('<div class=submitBg></div>').appendTo(.emailEditContainer);
$('<div class=submitLoadingCont><img class=submitLoading src=images/mypreferences/loading.gif width=50 height=50 /></div>').appendTo(.emailEditContainer);
}
});


I am using asp.net email validation - it looks something like this:



<asp:RegularExpressionValidator Display=Dynamic ValidationGroup=PrimarySubmit ID=RegularExpressionValidator1 runat=server ValidationExpression=w+([-+.']w+)*@w+([-.]w+)*.w+([-.]w+)* ControlToValidate=tbEmail1 ErrorMessage=Invalid email address -  />

More From » jquery

 Answers
4

You should check the email validity using a regexp



var re = /^(([^<>()[]\.,;: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,}))$/

$('#btnEmail1Submit').live (click, function() {
if(!email.match(re)) {
alert('invalid email');
return false;
}
$('<div class=submitBg></div>').appendTo(.emailEditContainer);
$('<div class=submitLoadingCont><img class=submitLoading src=images/mypreferences/loading.gif width=50 height=50 /> </div>').appendTo(.emailEditContainer);
});


The regexp comes from Validate email address in JavaScript?


[#91425] Tuesday, June 28, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
darennevina

Total Points: 422
Total Questions: 128
Total Answers: 105

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
;