File "code03.html"

Full Path: /home/analogde/www/Design/fileman/Fusion/code03.html
File size: 2.44 KB
MIME-type: text/html
Charset: utf-8

<!DOCTYPE html>
<html>
  <head>
    <title>How to Allow Only Positive Numbers in the Input Number Type</title>
	
	<script src="https://code.jquery.com/jquery-git.js"></script>
	
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

	
  </head>
  <body>
  
  <input type="text" id="yourTextboxIDHere" />
  
  <script>
	document.getElementById('yourTextboxIDHere').onkeypress = function (e) {
        // 46 is the keypress keyCode for period     
        // http://www.asquare.net/javascript/tests/KeyCode.html
        if (e.keyCode === 46 && this.value.split('.').length === 2) {
            return false;
        }
    }
	</script>
  
  <script>
  
  //document.write("Hello World!");
  
   console.log("riri ...");
  
  var num = "00378";
      document.write("Original number was : " + num);

      var int_num = parseInt(num,10);
      document.write("<br>Parsed number is : " + int_num);
  
  var num = 000123;
  
  let text = num.toString();
  
   console.log(text);
  
  var res = parseInt(text);

 
  
alert((num + "").length);
  console.log(typeof num); // string
  //
	const num1 = 13.4530000;
	const result1 = parseFloat(num1);
	console.log(result1); // ️ 13.453
  
  jQuery(document).ready(function() {
    $('.float-number').keypress(function(event) 
	{
		
		var val = this.value;
   if(val.charAt(0) === '.')
   {
     this.value = ('0'+val); 
	 alert("top");
   }
	
        if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
            event.preventDefault();
        }
    });
});
  
  </script>
  
  
   Enter Number:
        <input type="text" name="number" value="" class="float-number">
   
  
  <h1>Score</h1>
   <p>Rank:
      <input type="text" class="numbers" value="" />
   </p>
   <p>Marks:
      <input type="text" class="numbers" value="" />
   </p>
  
  <script>
      $('.numbers').keyup(function () 
	  {
         this.value = this.value.replace(/[^0-9\.]/g,'');
      });
   </script>
   
   <h1>Score</h1>
   <p>Rank:
      <input type="text" class="num" value="" />
   </p>
   <p>Marks:
      <input type="text" class="num" value="" />
   </p>
  
   <script>
      $('.num').keypress(function (e) {
         if (String.fromCharCode(e.keyCode).match(/[^0-9\.]/g)) return false;
      });
   </script>
  
    <input type="number" min="0" onkeypress="return (event.charCode !=8 && event.charCode ==0 || (event.charCode >= 48 && event.charCode <= 57))">
  </body>
</html>