Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

regex for numbers and decimals only

const source = document.getElementById('source');
source.addEventListener('input', allowOnlyNumberAndDecimals);

function allowOnlyNumberAndDecimals(e) {
  let str = e.target.value
  const regExp = /^(d+(.d+)?)$/

  let status = regExp.test(str) ? 'valid' : 'invalid'

  console.log(status + ' : ' + source.value)
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: css in console.log 
Javascript :: react aos 
Javascript :: convert number to comma separated format javascript 
Javascript :: remove first select option jquery 
Javascript :: npm check updates 
Javascript :: add button in table using javascript 
Javascript :: npm remove dev dependencies from node_modules 
Javascript :: empty select option jquery 
Javascript :: required false jquery 
Javascript :: styling scrollview height in react native 
Javascript :: add classnames to body 
Javascript :: set width screen angular 
Javascript :: javascript update attribute 
Javascript :: jquery form id submit 
Javascript :: create element ns svg 
Javascript :: js save local storage 
Javascript :: jquery change font size 
Javascript :: sequelize exclude attribute 
Javascript :: track window resize in vue 
Javascript :: jquery delete request 
Javascript :: how to submit using checkbox 
Javascript :: header ejs 
Javascript :: nodejs ask for input 
Javascript :: disable click event jquery 
Javascript :: javascript how to get a random element from an array 
Javascript :: remove quotes from array javascript 
Javascript :: js change video src 
Javascript :: jquery remove option from select by value 
Javascript :: RegExp validation for password explained 
Javascript :: javasctipt unix timestamp from date 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =