CutomValidator to validate email address ignoring space at the end in .NET

March 19, 2009 at 8:13 am (.NET, ASP.NET, Technical) (, , )

We have compare validator in .NET to Compare the value entered by the user in an input control with the value entered in another input control, or with a constant value. Click here explore more on CompareValidator.

I had a unique requirement to validate the Email address in the two controls ignoring space at the end. I explored more and found a solution using the CustomValidator. Click here explore more on CustomValidator.

I have mentioned the code below

Added the following CustomValidator in the page:

<asp:CustomValidator ID=”CompareEmailAddress” runat=”Server” ClientValidationFunction=”CompareEmailAddress” ErrorMessage=”*” EnableClientScript = “true” ></asp:CustomValidator>

JS Function to compare the Email address ignoring space:

function CompareEmailAddress(source,args)
{
email = rtrim(document.getElementById("ctl00_ContentPlaceHolder1_EmailCtl").value) // Getting trimmed email address from FIRST input control
verifyemail = rtrim(document.getElementById("ctl00_ContentPlaceHolder1_VerifyEmailCtl").value) // Getting trimmed email address from SECOND input control
if(email == verifyemail)
{
args.IsValid = true;
}
else
{
args.IsValid =false;
}
}

Advertisements

1 Comment

  1. steve said,

    Thanks so much!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: