I have a time mask, it accepts +1000h, but I wanted to set:00 after the hours
return varTemp
.replace(/\D/g, "")
.replace(/(\d{2,4})(\d{2}$)/, "$1:$2")
};
In this mask, : stays between hours and minutes. But I wanted to leave :00 fixed, without the minutes.
const maskHours = (value) => {
return (
value
.replace(/\D/g, "")
.replace(/(\d{2})/, "$1:00")
);
};
In this mask, the value :00 is fixed, but the result is not good.
Thanks to whoever helps me!
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))