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 6897587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:11:14+00:00 2026-05-27T07:11:14+00:00

I am using Asp.Net MVC 3 and I am adding a validator later in

  • 0

I am using Asp.Net MVC 3 and I am adding a validator later in the lifecycle through jquery with jquery.validate using [this code][1]:

Thanks to the answer of redsquare I added a method like this:

$.validator.addMethod(
        "regex",
        function(value, element, regexp) {
            var check = false;
            var re = new RegExp(regexp);
            return this.optional(element) || re.test(value);
        },
        "Please check your input."
);

now all you need to do to validate against any regex is this:

$("Textbox").rules("add", { regex: "^[a-zA-Z'.\s]{1,40}$" })

The validation is working fine, but the actual message isn’t showing up anywhere… what am I doing wrong? Thank you.

  • 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-27T07:11:15+00:00Added an answer on May 27, 2026 at 7:11 am

    I had the same issue. Never found what was causing the issue and I’ve ended up using MVC unobtrusive validation by assigning validation attributes to my input fields :

    so assuming you’ve got a #Textbox input :

    <input class="text-box" id="Textbox" name="Textbox" type="text" value="">
    

    Easy way to turn on the validation is just to assign data-val-* attributes :

    $(document).ready(function(){
       $('#Textbox').attr('data-val','true'); // turn on validation
       $('#Textbox').attr('data-val-regex','The input does not match the validation pattern'); // message to show when validation fails
       $('#Textbox').attr('data-val-regex-pattern',"@^[a-zA-Z&#39;.\s]{1,40}$"); //regex
    });
    

    This is they way I do it on my website and it works. The way you call your validation may collide with they way how Microsoft implemented jQuery validator, however I couldn’t find where that is

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

Sidebar

Related Questions

Using asp.net MVC I'd like to do this inside a view: <%= Html.TextBox(textbox1, null,
Using ASP.NET MVC + jQuery : I need to use some values owned by
I am currently using ASP.NET MVC and Entity Framework Code First using the repository
I'm using Amazon .NET SDK, and adding file from my ASP.NET MVC app is
At the moment I am building a big project using: ASP.Net MVC 4 jQuery
Have: Using ASP.NET MVC 2, DataAnnotationsModel based server validation, and client validation with jQuery.
I am using ASP.NET MVC 2 with nhibernate. I have this Sales class. Sales
how many methods for adding style sheets in a page using Asp.net MVC
I'm using the jquery libs in my ASP.NET MVC application in the head of
I'm using ASP.Net MVC Design pattern and when adding a controller to my application

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.