Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Just allow Intergers in Input Field

//Use this DOM

<input type='text' onkeypress='validate(event)' />



//JS Script
function validate(evt) {
  var theEvent = evt || window.event;

  // Handle paste
  if (theEvent.type === 'paste') {
      key = event.clipboardData.getData('text/plain');
  } else {
  // Handle key press
      var key = theEvent.keyCode || theEvent.which;
      key = String.fromCharCode(key);
  }
  var regex = /[0-9]|./;
  if( !regex.test(key) ) {
    theEvent.returnValue = false;
    if(theEvent.preventDefault) theEvent.preventDefault();
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: mongoose lookup array of objects 
Javascript :: concat vs spread 
Javascript :: Constructing a URL from component parts and getting the constructed string 
Javascript :: regex remove whitespace 
Javascript :: concurrently package usage 
Javascript :: auto refresh vue pwa 
Javascript :: React clock via props 
Javascript :: aysnc and await response data usage 
Javascript :: vite displays blank page in docker container 
Javascript :: linux Error HH604: Error running JSON-RPC server 
Javascript :: row no datatable 
Javascript :: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.0:compile 
Javascript :: how to multiply two array in javascript 
Javascript :: menu with dynamic submenu in javascript 
Javascript :: shell curl path of json file as parameter without temporal file 
Javascript :: auto linting and testing in react tyescript 
Javascript :: transform js to typescript 
Javascript :: TypeError: Invalid schema configuration: `True` is not a valid type at path `id.required`. See https://bit.ly/mongoose-schematypes for a list of valid schema types.] 
Javascript :: useMediaquery hook react 
Javascript :: Plumsail change the size of the dialog window 
Javascript :: (state.isLoggedIn = function() {return false}) react redux 
Javascript :: FILTER METHOD. IMPORTANT 
Javascript :: Angular /Javascript- How can I shrink Sticky header on scroll functionality 
Javascript :: angularjs How to set code view as deafult instead of tree in jsoneditor 
Javascript :: Angular js Directive to Fire "click" event on pressing enter key on ANY element 
Javascript :: I am getting an error "createSpyObj requires a non-empty array" with running unit tests, which were executed perfectly before 
Javascript :: how to make colspan of table footer flexible with javascript/jQuery 
Javascript :: setup app files in node js 
Javascript :: Javascript if time is between 7pm and 7am do this? Javascript If Statement Time Action 
Javascript :: javascript get elemet last of array 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =