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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:43:53+00:00 2026-06-12T05:43:53+00:00

I have a project that I am developing using MVC 3 using Razor views.

  • 0

I have a project that I am developing using MVC 3 using Razor views.

I have a Decimal data type where the user can enter an amount. The data is submitted to a 3rd party where they insist the amount has a maximum of 2 decimal places. The amount must be greater than zero. The maximum amount varies depending on a value retrieved from the database. So I can’t hard code a maximum range of say 9999.99.

Example:- Let’s say the maximum amount for the current transaction is 123.45. I need to validate that the amount the user enters in the text box is between 0.01 and 123.45. If the user enters 123.46 this would be invalid because it exceeds the maximum. If the user enters 100.123 this would also be invalid because it would exceed the maximum of 2 decimal places.

Research so far… I thought I would try and solve the decimal places issue first. I was wondering if applying this to my model would work…

<DisplayFormat(ApplyFormatInEditMode:=True, DataFormatString:="{0.00}")>
Public Property PaymentAmount As Decimal

View:-

@Html.TextBoxFor(Function(model) model.PaymentAmount)

… but this just seems to do nothing.

Questions:-

  1. How can I create validation for a range restricted to 2 decimal places that accepts a value from 0.01 to X (where X is a maximum pre-determined value returned from the database prior to displaying the view) ?

  2. Can this also work with unobtrusive client-side validation?

I was thinking about creating a custom validation attribute and also hook this up for client-side validation which I think would work, but seems way like overkill for something that on the face of it would seem like a very simple issue.

  • 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-06-12T05:43:54+00:00Added an answer on June 12, 2026 at 5:43 am

    I think you need to get maximum amount of a transaction from database. then you need to write like,

    <input type="text" pattern="^\d*\.?\d{0,2}$" id="txtAmount"/>
    <input type="button" id="btnSubmit" onclick="return ValidateAmount(@Model.MaxAmount)"/>
    
    in script block
    
    function ValidateAmount(amt)
    {
      var useramount=$('txtAmount').val();
      if(useramount>amt)
    {
    alert('max amount exceeded.etc');
    return false;
    }
    else
    {
    return true;
    }
    }
    

    if the max amount of a transaction is fixed then there might be no issues you can use directly in javascript code. Hope it helps.

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

Sidebar

Related Questions

I using MVC for developing a web project in Java. My problem is that
I have a client's Django project that I'm developing locally, using Mercurial for version
I have a project that using some third-party libraries. My questions is how to
I have a project that is coded in C. I can build it, change
I am developing a medium sized ASP.NET project using ASP.NET MVC and Entity Framework.
I'm using NaturalDocs to generate code documentation for a Flash project that we're developing
Currently in the early stages of developing a very large project using ASP.Net MVC.
I have a project that I am developing built off CodeIgniter. The main part
I have project where i'm developing an Android App using a lot of existing
I have a framework based project that I'm using SVN to version control. I

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.