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

  • SEARCH
  • Home
  • 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 4576462
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:12:34+00:00 2026-05-21T20:12:34+00:00

Edit 02/05/2011 Ok, so i need to make my validation clientside, so I need

  • 0

Edit 02/05/2011

Ok, so i need to make my validation clientside, so I need what asked for below in c# to actually be in jquery. I will also be validating server side so I would appreciate more input there.

Original Question

Well, im on a real noob question trip today!!!

My previous question was for a specific regex. Now I have it and it works..how can I roll it out over multiple text boxes? I don’t want to use multiple Regular Expression Validation tools as they would clutter up my design space and I don’t think it’s a very elegant solution (It’s for a degree project)

Is there a method I could write? Along the lines of

public validator(string)
{
   doessomething.tostring
   return true/false
}

and access by

if (validator(txtsomething.text.tostring()) = true)
{
  Dothis
}

else
{
  dothis
}

Please be patient if my question is garbage 🙂
Thanks“

  • 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-21T20:12:35+00:00Added an answer on May 21, 2026 at 8:12 pm

    How about creating a custom control? I’ve edited my answer to include jQuery as well as server side validation. I don’t know what regex you’re using so I’ve just used a simple one testing for letters only.

    javascript (also include the jQuery file):

    <script language="javascript" type="text/javascript">
        function validateText(source, args) {
    
            var allTextFieldsValid = true;
    
            $(".noNumbers").each(function () {
                if (!/^[a-zA-Z]*$/.test(this.value)) {
                    allTextFieldsValid = false;
                }
            });
    
            args.IsValid = allTextFieldsValid;
        }
    
    </script>
    

    .aspx page:

    // set a specific css class on the textboxes you want to check so that jQuery can
    //  find them easily
    <asp:TextBox ID="TextBox1" runat="server" CssClass="noNumbers"></asp:TextBox>
    <asp:TextBox ID="TextBox2" runat="server" CssClass="noNumbers"></asp:TextBox>
    <asp:Button ID="SubmitButton" runat="server" Text="submit" OnClick="Submit_Click" />
    
    <asp:CustomValidator ID="MyValidator" runat="server" 
            OnServerValidate="Text_Validate" Text="Oops, sorry, no numbers!" 
            ClientValidationFunction="validateText"></asp:CustomValidator>
    

    code behind:

    protected void Submit_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                // do stuff
            }
            else
            {
                // do other stuff
            }
        }
    
        protected void Text_Validate(object source, ServerValidateEventArgs args)
        {
            args.IsValid = true;
    
        // I've done each textbox by id, but depending on how many you might want to loop through the controls instead
    
            if (!IsTextValid(TextBox1.Text))
            {
                args.IsValid = false;
            }
    
            if (!IsTextValid(TextBox2.Text))
            {
                args.IsValid = false;
            }
        }
    
        private bool IsTextValid(string myTextValue)
        {
            string myRegexString = @"^[a-zA-Z]*$";
    
            return Regex.IsMatch(myTextValue, myRegexString);
        }
    

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: OK, I believe the following solutions are valid: Use the jQuery AOP plugin.
EDIT 2 Okay, based on the advice on the answers below I eliminated my
EDIT: There's now a doc page on this so this question is irrelevant, also
For an asp.Net MVC project, I will need to handle large files( mostly 200-300Mo,
EDIT 22 March 2011 : This question is no longer that relevant since Youtube
Edit: also happens with $('body').width() and window.outerWidth API 2.3.3 HVGA Before and after rotating
Need help with a wordpress problem. I need to edit the query.php to ONLY
I need to develop an application that will periodically check data from a XML
I am working on some CRM 2011 Online customisations and I need to get
EDIT: Duplicate of Should Entity Framework Context be Put into Using Statement? I've been

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.