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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:22:14+00:00 2026-05-25T02:22:14+00:00

I am using jquery validation plugin for clientside validation of a form. I have

  • 0

I am using jquery validation plugin for clientside validation of a form.

I have a field StandardPrice which is required and needs to be a number. The validation code below works perfect.

I have another field in a form called MinPrice that is optional but I do want to validate that if a user puts something in there that it is a number. I thought by removing the required: true but still having the number: true it would support this but it seems like its not allowing me to leave this field blank (even though I don’t have required: true set)

Does jquery validation plugin support validating a field IF its populated but leaving it alone if its blank.

Here is my code:

 $("#productForm").validate({
     rules: {
         StandardPrice: {
             required: true,
             number: true
         },
         MinPrice: {
             number: true
         }
     }
 });

Here is a screenshot of the validation when the field is empty:

enter image description here

and here is my html output (my actual code is using a lot of HTML.helpers() and Html.ValidationMessageFor()

 <form action="/Product/EditProduct" id="productForm" method="post">    <fieldset>
    <legend>Product</legend>

    <div class="editor-label">
        <label for="Product_Name">Name</label>
    </div>

    <div class="editor-field">
        <input class="required" id="Product_Name" name="Product.Name" style="width:450px;" type="text" value="Linzer Tart" />
        <span class="field-validation-valid" data-valmsg-for="Product.Name" data-valmsg-replace="true"></span>
    </div>

    <div class="editor-label">

        <label for="Product_StandardPrice">StandardPrice</label>
    </div>
    <div class="editor-field">
        <input data-val="true" data-val-number="The field StandardPrice must be a number." data-val-required="The StandardPrice field is required." id="Product_StandardPrice" name="Product.StandardPrice" style="width:45px;text-align:right;" type="text" value="1.50" />
        <span class="field-validation-valid" data-valmsg-for="Product.StandardPrice" data-valmsg-replace="true"></span>
    </div>

    <div class="editor-label">
        <label for="Product_MiniPrice">MiniPrice</label>

    </div>
    <div class="editor-field">
        <input data-val="true" data-val-number="The field MiniPrice must be a number." data-val-required="The MiniPrice field is required." id="Product_MiniPrice" name="Product.MiniPrice" style="width:45px;text-align:right;" type="text" value="0.00" />
        <span class="field-validation-valid" data-valmsg-for="Product.MiniPrice" data-valmsg-replace="true"></span>
    </div>

    <input data-val="true" data-val-number="The field Id must be a number." data-val-required="The Id field is required." id="Product_Id" name="Product.Id" type="hidden" value="102" />

    <p>
        <input type="submit" value="Save" />

    </p>
</fieldset>

  • 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-25T02:22:14+00:00Added an answer on May 25, 2026 at 2:22 am

    number: true should work as you expect as seen in this live demo.

    • leave the field blank => the form submits
    • enter a valid number in the field => the form submits
    • enter an invalid number => an error message is shown and the form doesn’t submit

    After showing your markup it seems that you have some inconsistency between your field names and your jQuery validate names. For example your input is named Product.StandardPrice, not StandardPrice which is what you are using in your jQuery.validate. So none of your validate rules actually will apply as it doesn’t have any corresponding form element. So fix it:

    $("#productForm").validate({
         rules: {
             'Product.StandardPrice': {
                 required: true,
                 number: true
             },
             'Product.MiniPrice': {
                 number: true
             }
         }
    });
    

    Also notice that it should be Product.MiniPrice and not Product.MinPrice. Please be consistent.

    Remark: looking at your markup it is pretty clear that this is generated by ASP.NET MVC 3 HTML helpers. Why are you using custom jQuery.validate rules instead of the default unobtrusive ones?

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

Sidebar

Related Questions

I am using jquery validation plugin to validate my form. I have one field
I am using jquery validation plugin for form validation. I have added a custom
I have a form that is using jQuery Validate plugin for client side validation,
I am using jquery validation plugin and zend framework. I have my form in
I am using the jQuery Validation plugin I have the following code in an
I am using jQuery validation plugin (http://bassistance.de/jquery-plugins/jquery-plugin-validation/) Following code is a part of form
I'm using a jquery validation plugin First I add the validation to the form:
I am using the JQuery Validation plugin for client side form validation. In addition
I am using the jquery validation plugin (bassistance.de/jquery-plugins/jquery-plugin-validation/id) for a bit of client-side form
I have a mixed client-side/server-side validation using jQuery validation plugin. The validation happens on

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.