Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
Validating C#'s Long Variable value in Javascript

I have a form wherein a user can enter a value associated with a nullable long property of my ViewModel. But because I have an 'onblur' event on that text box, I am trying to validate the entered value in my textbox.onblur() event and ensure that it does not exceed the C#'s, long.MaxValue. Here is my "blur" code on that text box.

var value = $(this).val();
console.log(value > 9223372036854775807);

if (value<= 1 || value > 9223372036854775807) {             
            $('#divValueError').text("Invalid Value!");
            return false;
        }

But Javascript is returning false on that console.log statement if I enter 9223372036854775808. How do I check if the number entered by the user falls within the limits of a C# long value?

I understand 64 bit numbers are not supported by Javascript. I also could not get my [Range] data annotation on that property to fire before this blur event is called, even though I tried

if (!$(this).valid()) {

            return false;
        }

Please let me know how I can throw a client side error if the value entered by the user falls outside the boundaries of a C#'s long data type value.

Thanks!

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Perfect Answer : I am Providing example that will solve your problem. In this , you first have to convert your value in string and then in biginteger. Reference link added for better guidance.

var valuecompare = BigInt("9223372036854775808");
var valuebase = BigInt("9223372036854775807");

console.log(valuecompare);
console.log(valuebase);

if (valuecompare > valuebase) {             
            console.log('greater value');
        }
else{
    console.log('less value');
}

Reference Link : https://www.smashingmagazine.com/2019/07/essential-guide-javascript-newest-data-type-bigint/

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!