JavaScript Input to allow for only one decimal point input allow only numbers,input allow only alphanumeric,input allow

I am trying to format a number upon input, where you can only insert valid numbers. I have everything working except for the decimal. The input box allows me it insert as many decimals as I would like, but I would only like to allow for one (see the last replace()).

element.oninput = e => {
    let value = e.currentTarget.value;
    let result = value
        // Remove anything that isn't valid in a number
        .replace(/[^0-9-.]/g, '')
        // Remove all dashes unless it is the first character
        .replace(/(?!^)-/g, '')
        // Remove all periods unless it is the last one
        .replace(/(?!)\./g, '');
    element.value = result;
}

https://jsfiddle.net/c4f1L3kv/1/

Here are some valid inputs:

123.123
-123.12
123
-123
.123
-.123

Here are some invalid inputs:

123-123
1-2-3
123.123.123
123-123..12
Answer:1

updated. I have stored my data in an array of tuples: called $scope.unique. basically it looks like this: [["Chris Ivory", "Alfred Morris"], ["CJ", "DJAX"], ["DJ", "CX"]["Willie", "Fred]]. The ...

updated. I have stored my data in an array of tuples: called $scope.unique. basically it looks like this: [["Chris Ivory", "Alfred Morris"], ["CJ", "DJAX"], ["DJ", "CX"]["Willie", "Fred]]. The ...

  1. ng repeat with arrays
  2. repeat arrays matlab
  3. repeat arrays python
  4. repeat arrays
  5. ng-repeat with two arrays
  6. ng-repeat with multiple arrays
  7. ng-repeat with 2 arrays
  8. ng-repeat with nested arrays

Let's consider a definition as function Stone() { this.x = 0; this.y = 400; }; I instantiate an object var st = new Stone; var ll = [st]; var remov = ll.splice(0, 1); ...

Let's consider a definition as function Stone() { this.x = 0; this.y = 400; }; I instantiate an object var st = new Stone; var ll = [st]; var remov = ll.splice(0, 1); ...

  1. javascript splice return object

I am working with Jquery/javascript/html. I am trying to display a button inside of tags in my table. I am appending the information into/onto a section on my html page. Code is as follows: <html&...

I am working with Jquery/javascript/html. I am trying to display a button inside of tags in my table. I am appending the information into/onto a section on my html page. Code is as follows: <html&...

  1. jquery append button to div
  2. jquery append button with onclick
  3. jquery append button click not working
  4. jquery append button text
  5. jquery append button with click event
  6. jquery append button
  7. jquery append button not working
  8. jquery append button onclick not working
  9. jquery append button to td
  10. jquery append button click
  11. jquery append button to table row
  12. jquery append button to body
  13. jquery append button to li
  14. jquery append button with id
  15. jquery append button to form
  16. jquery append button value
  17. jquery append button to table
  18. jquery append button to input
  19. jquery append button class
  20. jquery append button to element

On the moment I am building code to show text when I hover on a certain div. I am able to produce this, but it's static and I can't reproduce it. I would like to make it dynamic. I have a single ...

On the moment I am building code to show text when I hover on a certain div. I am able to produce this, but it's static and I can't reproduce it. I would like to make it dynamic. I have a single ...

  1. show/hide div jquery
  2. show/hide div javascript
  3. show/hide div css
  4. show/hide div on link click
  5. show/hide div on page load javascript
  6. show hide divs
  7. show hide divs jquery
  8. show hide divs javascript
  9. show hide divs on click
  10. show hide div with transition css
  11. show hide div on scroll position
  12. show hide div using jquery
  13. show hide div using javascript
  14. show hide div in angular 6
  15. show hide div javascript onclick
  16. show hide div with animation javascript
  17. show hide div on button click
  18. show hide div codepen