Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6766509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:50:22+00:00 2026-05-26T14:50:22+00:00

I had been created text box custom validation control and I’m using this in

  • 0

I had been created text box custom validation control and I’m using this in my aspx page and its working great up to finding length means if it is empty means it’ll validate correctly
but now wanted to enhance this, like if I wanted to enter my email id then first condition is, it should not be empty, second is it should of the format abc@abc.com.
and if it is empty means I need to show error msg like ‘please enter email id!!’ and if it is not in above format then show ‘please enter correct email id!!’.

here is my code,
TextboxCustomValidation.aspx

namespace TextboxCustomValidator
{
    public class TextboxCustomValidation : BaseValidator
    {

        protected override void OnPreRender(EventArgs e)
        {
            if (this.DetermineRenderUplevel() && this.EnableClientScript)
            {
                Page.ClientScript.RegisterExpandoAttribute(this.ClientID, "evaluationfunction", "CheckTextboxvalid");
                this.CreateJavaScript();
            }
            base.OnPreRender(e);
        }

        protected void CreateJavaScript()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(@"<script type=""text/javascript"">function CheckTextboxvalid(ctrl){");
            sb.Append(@"var txtlength = document.getElementById(document.getElementById(ctrl.id).controltovalidate);");          
            sb.Append(@"if(txtlength.value.length>2){");
            sb.Append(@"return true; }else");
            sb.Append(@" {return false;} ");
            sb.Append(@"}</script>");
            Page.ClientScript.RegisterClientScriptBlock(GetType(), "JSScript", sb.ToString());
        }

        protected override bool ControlPropertiesValid()
        {
            TextBox txt = FindControl(ControlToValidate) as TextBox;
            return (txt != null);
        }

        protected override bool EvaluateIsValid()
        {
            return CheckTextboxIsValidorNot();
        }

        protected bool CheckTextboxIsValidorNot()
        {
            TextBox txtControlName = (TextBox)FindControl(this.ControlToValidate);
            if (txtControlName.Text.Length > 0)
                return true;
            else
                return false;
        }

    }
}


**MyTextBoxValidation.aspx**

<%@ Register TagPrefix="TCV" Namespace="TextboxCustomValidator" %>
<body>
    <form id="form1" runat="server">
    <div>
        UserName :
        <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
        <TCV:TextboxCustomValidation ControlToValidate="txtUserName" ErrorMessage="Please enter username !!"
            EnableClientScript="true" runat="server"></TCV:TextboxCustomValidation>
        <asp:TextBox ID="txtEmailId" runat="server"></asp:TextBox>
        <TCV:TextboxCustomValidation ControlToValidate="txtEmailId" ErrorMessage="please enter txtEmailId!!" EnableClientScript="false"
            runat="server">
        </TCV:TextboxCustomValidation>
        <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="Save_Click" />
    </div>
    </form>
</body>
</html>

help me,
any reply means will be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:50:23+00:00Added an answer on May 26, 2026 at 2:50 pm

    Should work like this

    public bool ValidateMail(string mailAdress)
    {
        if (String.IsNullOrEmpty(mailAdress))
        {
            ShowError("please enter email id!!");
            return false;
        }
        //The regular expression matches at:
        //[anything]-@-[anything except "."]-.-[2 or 3 chars after the "."]
        else if (!Regex.Match(mailAdress, @".+\@[^\.]+\..{2,3}")
                                .Length == mailAdress.Length)
        {
            ShowError("please enter correct email id!");
            return false;
        }
        return true
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having issues with a custom check box control for a while
I had been working on server side(c#) for a couple of years. But now
Our Dev team had been developing enterprise web page more than 2 years ago.
I've been trying to get this really simple example of using AJAX with JQuery
I've been working on this project for a while, it's a new language for
I had been happily coding along on a decent sized solution (just over 13k
I had been steering away from C# for a while, because it was just
I had been wondering for quite some time on how to manager memory in
I had been asked to build crystal reports for an application, i used the
I've had been hearing about test driven development for a couple years now, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.