Answers for "input field take only number and one comma"

0

input field take only number and one comma

function checkKey() {
    var clean = this.value.replace(/[^0-9,]/g, "")
                           .replace(/(,.*?),(.*,)?/, "$1");
    // don't move cursor to end if no change
    if (clean !== this.value) this.value = clean;
}

// demo
document.querySelector('input').oninput = checkKey;
Posted by: Guest on May-28-2020

Code answers related to "input field take only number and one comma"

Code answers related to "Javascript"

Browse Popular Code Answers by Language