Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

42 lines
849 B

  1. // Strips non-digits from an input box event and returns it's rounded integer.
  2. // It also preserves current valid entry (.)
  3. export function strip(e) {
  4. let valid = e.target.value.match(/\d+\.?\d?\d?/)?.[0] ?? ""
  5. e.target.value = valid
  6. return Number(valid || 0)
  7. }
  8. export function stripLetters(e) {
  9. let value = (e.target.value.replace(/[^\w\s]/g, '').slice(0, 20) || '')
  10. e.target.value = value
  11. return value
  12. }
  13. export function stripInt(e) {
  14. let value = parseInt(e.target.value.replace(/\D/g, '') || 0)
  15. e.target.value = value
  16. return value
  17. }
  18. export function stripPerc(e) {
  19. let num = strip(e)
  20. if (num > 100) {
  21. num = 100
  22. e.target.value = num
  23. }
  24. if (num < 0) {
  25. num = 0
  26. e.target.value = num
  27. }
  28. return num
  29. }
  30. // Print number of cents as a nice string of dollars
  31. export function format(num) {
  32. return (num/100).toLocaleString(2)
  33. }