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

  • Home
  • SEARCH
  • 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 5850531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T13:09:12+00:00 2026-05-22T13:09:12+00:00

Basically, I have a user input field where a user can enter a number.

  • 0

Basically, I have a user input field where a user can enter a number. They would like to also be able to enter equations in the input field as well.

Something like “874.45 * 0.825 + 4000” and have that converted to its real numeric value.

All the solutions I found point to the dreaded eval() method. Especially with this being a user entered field, I’m concerned about just running eval(“874.45 * 0.825 + 4000”) and hoping to get a number out the back end.

I suppose I could do a web service call back to the server (ASP.NET), but I’m afraid a slight delay will create some frustration from the user.

Does anyone know of either a good technique or existing libraries?

  • 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-22T13:09:13+00:00Added an answer on May 22, 2026 at 1:09 pm

    What you really need here is an “expression parser”, because you’re trying to allow users to express their values using a small domain-specific language.

    The basic mechanics work like this:

    1. Tokenize their expression into operators and operands.

    2. Based on the order of operations (e.g, where multiplication is evaluated with higher priority than addition), push the operators and operands onto a stack.

    3. Pop the operands from the stack and push intermediate results back onto the stack. Repeat until the stack is empty.

    I’ve done this a gazillion times for different “little languages” throughout my projects. But never in javascript. So I can’t directly recommend a suitable parsing library.

    But a quick googling reveals “PEG.js”. Check it out here:

    http://pegjs.majda.cz/

    All of the examples in their documentation are for exactly the kind of “expression parser” you’re trying to build.

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

Sidebar

Related Questions

we are running a click-to-call service, my idea is basically like this: website have
I am doing a little app with JQuery, using drag-n-drop for the interface. Basically,
So I am having this problem wit my download link. Basically my previous way
I am using Microsoft Visual Studio Professional 2010. (Also SQL Management Studio for my
I have this controller set up for a login: <?php class Login extends Controller
I have a table in my database which has information about a bunch of
I'm trying to write a sh coding to get the user to authenticate the
I am very confused over something and was wondering if someone could explain. In
I was hoping for a little help. I am currently using some of the
Ok so I am having a problem with doing multiple forms in rails. here

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.