|
- // Strips non-digits from an input box event and returns it's rounded integer.
- // It also preserves current valid entry (.)
- export function strip(e) {
- let valid = e.target.value.match(/\d+\.?\d?\d?/)?.[0] ?? ""
- e.target.value = valid
- return Number(valid || 0)
- }
-
- export function stripLetters(e) {
- let value = (e.target.value.replace(/[^\w\s]/g, '').slice(0, 20) || '')
- e.target.value = value
- return value
- }
-
- export function stripInt(e) {
- let value = parseInt(e.target.value.replace(/\D/g, '') || 0)
- e.target.value = value
- return value
- }
-
- export function stripPerc(e) {
- let num = strip(e)
-
- if (num > 100) {
- num = 100
- e.target.value = num
- }
-
- if (num < 0) {
- num = 0
- e.target.value = num
- }
-
- return num
- }
-
- // Print number of cents as a nice string of dollars
- export function format(num) {
- return (num/100).toLocaleString(2)
- }
|