Easy Number Separator
A tiny, dependency-free JavaScript plugin that formats numbers while you type.
GitHub & docs CDN file1. Basic
Comma separator, letters are rejected.
easyNumberSeparator({
selector: '.ex-basic'
})
2. Custom separator
European style: . for thousands, , for decimals.
easyNumberSeparator({
selector: '.ex-custom',
separator: '.',
decimalSeparator: ','
})
3. Max decimals + raw value
At most 2 decimals; the raw number goes to another input.
easyNumberSeparator({
selector: '.ex-decimals',
maxDecimals: 2,
resultInput: '#raw-decimals'
})
4. Two inputs on one page
Each input keeps its own raw value.
easyNumberSeparator({
selector: '#price',
resultInput: '#price-raw'
})
easyNumberSeparator({
selector: '#qty',
resultInput: '#qty-raw'
})
5. Submit raw values
The form sends the unformatted number under the input's name.
easyNumberSeparator({
selector: '.ex-submit',
submitRaw: true
})
6. Disallow paste
Pasting is blocked here. Elsewhere, pasted text such as $1,234 USD is cleaned up.
easyNumberSeparator({
selector: '.ex-nopaste',
disallowPaste: true
})