Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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)
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #regex #numbers #decimals
ADD COMMENT
Topic
Name
2+1 =