score:0

use

const maskhours = (value) => {
  return (
    value
      .replace(/\d/g, "")
      .replace(/^(\d{2,4})\d+/, "$1:00")
  );
};

explanation

--------------------------------------------------------------------------------
  ^                        the beginning of the string
--------------------------------------------------------------------------------
  (                        group and capture to \1:
--------------------------------------------------------------------------------
    \d{2,4}                  digits (0-9) (between 2 and 4 times
                             (matching the most amount possible))
--------------------------------------------------------------------------------
  )                        end of \1
--------------------------------------------------------------------------------
  \d+                      digits (0-9) (1 or more times (matching
                           the most amount possible))

Related Query

More Query from same tag