Validating Confirm Email ID using Javascript

Posted by Self-Innovator under ASP.NET AJAX on 10/10/2012 | Points: 10 | Views : 3191 | Status : [Member] | Replies : 3
Hi,
In my registration form i am validating user email using javascript validation here i have conform email Id one more field i wanted to validate these also using javascript validation instead of compare validator control any Idea on this.below is my Email id Validation Javascript function.
Email ID(First)
function ValidateEmail(x)
{
var EmailExp=/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
if(x.value.match(EmailExp))
{
return true;
}
else
{
alert("Invalid Mail ID");
x.value="";
x.focus();
return false;
}
}


<asp:TextBox ID="txtEmail" onchange="ValidateEmail(this)" runat="server"></asp:TextBox>

Confirm Emai ID (Second Control)
I wanted to validate this also using javascript instead of Compare validator control

Join Hands Change lives
Thanks & Regards
Straight Edge Society



Responses

Posted by: Sourabh07 on: 10/15/2012 [Member] Starter | Points: 25

Up
0
Down
function ValidateEmail(x)
{
var EmailExp= /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

if(EmailExp.test(x) == false)
return false;
else
return true;
}

Please try this code...........here "x" is an Email Id you want to validate
eg: x = mahajan.sourabh07@yahoo.com

Sourabh07

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Self-Innovator on: 10/15/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi Sourabh ,
I guess the above code which you've posted will validate only for the email Id of a single control. But my requirement is to validate the email id & conform email id two controls without using compare validator server control while registering the users. I hope you've understand my req..

Join Hands Change lives
Thanks & Regards
Straight Edge Society

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sourabh07 on: 10/15/2012 [Member] Starter | Points: 25

Up
0
Down
Hi...

if it is so...then you might use onclient click event of the register button to check the values of both the textbox controls...if they are same then it will proceed to the server function else restricted at the design time..

try it, hope it will sort out the porblem without moving to the server side..



Sourabh07

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response