Emphasize the text box in "red" if the value is not a number, a number with a dot, or a comma

I am currently utilizing Bootstrap in order to implement some visual validation for the form fields:

<div class="span1" style="min-width: 20px;">
    <input type="number" min="0.1" max="40" step="0.1" value="1" data-field="numberField" class="input-mini" style="width: 40px">
</div>

Is there a way for the text box to display a red highlight when the input is not numeric, or contains commas or dots (euro format)?

Answer №1

Similar to the response above (upvoted) as it accomplishes most of the task, with the assumption based on your feedback that you're looking to add Bootstrap's warning class to the input element.

All the necessary classes can be found in Bootstraps' official documentation at getbootstrap.com. You'll need to apply the input classes, which are typically located on the "components" section of the website.

To achieve this, utilize jQuery's addClass() function following the instructions provided by @Reza:

var value = $("#inputId").val();
if(Math.floor(value) == value && $.isNumeric(value))
    $("#inputId").addClass('input-warning');

Answer №2

Implement an onBlur event triggering a CSS style when certain conditions are met:

let userInput = $("#inputId").val();
if(Math.floor(userInput) == userInput && $.isNumeric(userInput)) {
    $("#inputId").css('border', '1px solid red');
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring the inner workings of CSS shapes

http://jsfiddle.net/zth05v3q/ div { background:red; width:100px; height:100px; } div:after{ content: ''; position: absolute; display: block; border: 40px solid green; border-left-width: 15px; bord ...

Executing a javascript function numerous times

Here are a few examples: <div class="statement">text goes here</div> <div class="response"><input type="text" id="amount1" style="border: 0; color: #f6931f; font-weight: bold;" /></div> <div id="sli ...

Joomla template experiencing issues with script loading

I'm currently experimenting with using jQuery to dynamically display content on my Joomla website based on the date. You can check out the working demo on this jsfiddle link: http://jsfiddle.net/2BHLd/968/ $(function() { $(".DateDiv").each(function(i ...

Problem with adding new elements to nested objects and arrays in JavaScript

Here is the code snippet I am working with: let users2 = [ { _id: 'ab12ex', username: 'Alex', email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1f7e737a675f7e737a67317c4 ...

Exploring the power of Vue3 with Shadow DOM in web components

I've been experimenting with web components using Vue3 and I'm curious about how the Shadow DOM works. I encountered an issue where a third party library was trying to access elements using getElementById() and it was throwing an error because th ...

What is the best way to transfer Flow type properties from one React component to another?

I'm in the process of developing a component that will wrap another component known as Button. The tricky part is that the library where Button is defined does not expose the type of its properties. In order to properly assign types to my component, ...

Is it possible to have the Save Success Alert fade out only once?

After incorporating this code snippet, I implemented a fade effect on the success alert whenever it is triggered. However, I noticed that the fade effect only occurs the first time I click "save". Subsequent clicks do not trigger the fade effect, causing ...

Modify the value of Bootstrap's collapse button when it is clicked

Even after extensively searching the forum and Google, as well as reading numerous articles, I am still unable to successfully achieve what I want. My aim is to change the value of a button upon clicking it. Specifically, if the content is currently visibl ...

What is the best way to conceal a canvas or another item?

Within my main canvas, there are three smaller canvases and a text element. <canvas id="Background" width="350" height="300" style="border:6px solid black; position: absolute; left: 10px; top: 10px;"> </canvas> <canvas id="Canvas1" width ...

Using Regex in Javascript to locate unfinished items that start and finish with brackets

Can anyone assist me in utilizing regex to identify any incomplete items that start with {{. I have attempted to search for instances in the string that begin with {{ and are followed by letters (a-Z) but do not end with }}. However, my attempts always re ...

Steps for using selenium to select a radio button

Looking to leverage Selenium in Python 3.9 for button clicking automation. Link to the website https://i.stack.imgur.com/KWsKG.png The goal is to click on "Effective Date", then select "July 2021", and finally click "OK". Initially, the first two steps ...

Position the center button evenly between two images, aligned vertically using percentages

I'm attempting to achieve a specific layout that includes images scaling across Bootstrap breakpoints and a static button position. The challenge is maintaining the layout as depicted in the mockup, regardless of image size. The images are set to im ...

Begin one lesson, end all others

Looking for help with my expandable list menu that I created using jQuery. Here is the code snippet: $("#menu ul li ul").hide(); $("#menu ul li").click(function() { $(this).find("ul").slideToggle(); }); You can view the fully functional menu on jsFi ...

Use node.js and the Awilix modules to add parameters to a class that extends from a parent

Looking to establish a parameter in the child class and utilize it in the base class, I aim to access this variable initialized in the child constructor without invoking super() as I require specific services only in the parent. The child classes are ins ...

The Node.js Express framework seems to be failing to respond to incoming requests

I am currently utilizing the express web framework and attempting to send an $http request from angularjs. Despite passing data to the server through the client, the server is not receiving the request for reasons unknown to me. Can anyone offer some assis ...

Obtaining JSON information from AJAX with the help of express.js

After retrieving data from HandsOnTable, I am sending it to my Node.JS and Express.JS backend for storage. Following the example provided here (), I utilize json.stringify to format the data before transmitting it using an AJAX GET request. The challenge ...

Transforming Form Input into Request Payload for an AJAX Call

I'm facing a challenge in submitting my form data through a POST AJAX request and haven't been able to come across any solutions so far. Due to the dynamic creation of the form based on database content, I can't simply fetch the values usin ...

Can I send an AJAX request to JavaScript rather than ASP?

Currently, I am in the process of developing a content delivery network (CDN), and I am exploring the idea of using a jQuery AJAX call to a JavaScript file instead of an ASP file. The JavaScript file would be responsible for processing the input and then s ...

Issue with React video element not pausing

Hey there, I've been working on creating a custom video player in React and have encountered an issue. I'm trying to use the handlePlay function as an onClick event to play or pause the video. The state variable isPlaying is used to track the use ...

Adjusting webpage background with JavaScript

I've been struggling with this for the past six hours and can't seem to get it right. I've checked out various solutions on Stack Overflow, but nothing seems to work. What am I missing here?!? My html5 page doesn't have a background an ...