Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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;
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #input #field #number #comma
ADD COMMENT
Topic
Name
5+9 =