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

The Archive Base Latest Questions

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

I have a very simple contact form with fields like this: <label> First Name<em>*</em>

  • 0

I have a very simple contact form with fields like this:

<label>
    First Name<em>*</em>
    @Html.TextBox("txtFirstName", null, new { tabindex = "1"})
</label>

I want this field to be required so I’ve add some code to document ready:

$(function(){
    $("#contactForm").validate({
        rules: {
            txtFirstName: { required: true}
            /* also tried this */
            txtFirstName: "required"
        }
    });
});

However, at this point it won’t require the field. What seems crazy is that if I add a “required” class attribute like so:

@Html.TextBox("txtFirstName", null, new { tabindex = "1", @class="required"})

It will validate, but I need more complex rules than just required. I need to check that certain options are chosen in a select list then certain fields should or should not be required.

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

    I suspect that you have included the jquery.validate.unobtrusive.js script to your page. This script registers its own .validate handler on the form which obviously conflicts with yours. The jquery.validate.unobtrusive.js script is used when you have a view model decorated with data annotations to perform validation and those data annotations are translated into HTML5 data-* attributes on the generated input fields. Those HTML5 data-* attributes are then interpreted by the jquery.validate.unobtrusive.js script which registers a .validate handler on the form.

    If you want to define your own validation rules and register a custom .validate rules you will have to do it manually (as you did) and remove any traces of the built-in unobtrusive validation script from this page.

    The reason why validation works when you add the class="required" attribute on the input field is because the jquery.validate.unobtrusive.js picks it up and it includes it in its own rules when it configures the plugin by registering a .validate method on the form.

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

Sidebar

Related Questions

I have very simple select like this: SELECT * FROM table WHERE column1 IN
I have a very simple contact form on my site, Im looking for users
If I have a very simple http directory: default.html info.html contact.html etc... Should default.html
I have a very simple Java RMI Server that looks like the following: import
Have created simple Ajax enabled contact forms before that have around 12 fields -
I am trying to build a very simple Contact browser. I have a Collection
I'm designing a database application which stores simple contact information (First/Last Name etc.) and
I have a very simple model form, but for some reason, the code fails
I have a very simple form.I want to insert the form data in mysql
i have very simple problem. I need to create model, that represent element of

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.