Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

validateDouble

<!doctype html>
<html ng-app>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js"></script>
    <script>
        validateDouble = function validate( evt ) {
            var theEvent = evt || window.event;
                    console.log('double', theEvent);
    
            // Handle paste
            if (theEvent.type === 'paste') {
                key = event.clipboardData.getData('text/plain');
                    console.log('paste', key);
            } else {
            // Handle key press
                var key = theEvent.keyCode || theEvent.which;
                key = String.fromCharCode(key);
                    console.log('press', key);
            }
            var curValue = theEvent.target.value;
            var regex = curValue && curValue.indexOf( '.' ) >= 0 ? /[0-9]/ : /[0-9]|\./;
            if( !regex.test(key) ) {
                theEvent.returnValue = false;
                if(theEvent.preventDefault) theEvent.preventDefault();
            }
        };
    
    document.addEventListener("DOMContentLoaded", function(event) { 
        let input = document.getElementById("input1");
        input.setAttribute( 'onkeypress', 'validateDouble(event)' );    
    });

    </script>
  </head>
  <body>
    <div>
      <label>Name:</label>
      <input type="text" id="input1" ng-model="yourName" placeholder="Enter a double">
    </div>
  </body>
</html>

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.