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))
Source: stackoverflow.com
Related Query
- How do I leave a fixed value in a mask with regex?
- React how to make an input field with a fixed value combined with a dynamic value
- How do I split string value with Regex expression and return an array and object?
- How to change the value of a Context with useContext?
- How to mirror and resize the part of image with fixed width and height
- How to fix "Expected to return a value in arrow function" with reactjs?
- How to receive select value in handlesubmit function with formik react js?
- How do I call setState with the previous state plus an additional value in a redux connected controlled component?
- How to dynamically update the value for any input field with one event handler function, using hooks
- How to reload input value in React / Javascript with Virtual DOM?
- How to use meta tags with dynamic value in react js?
- How do I programatically fill input field value with React?
- How to set defaultValue, value={this.props.value}, and update the value of a text input with React?
- how to pass value with bindActionCreators?
- How to update state of a component with value from reducer state in react-redux?
- How can a function value is displayed in a HTML tag with a return value from addEventListerner click?
- How to update with React Hooks specific value of an array inside an object?
- How to enter only an integer value in TextInput with type="number"
- How to get the current value of animated values with option useNativeDriver set to true?
- How to mask password with MaterialTable
- How setState with one value work?
- How to set the value of inputs with ReactJS hooks?
- How to check the value of a nested React component in a unit test with Enzyme and Jest
- How to update a field value after action dispatched with redux
- how to calculate default value for react js state hook with a function?
- How can I keep my iterable value in loop with React and Redux?
- How to update and display first non-empty value on setState with react?
- How to use router for switching between components with a key value pair in react
- How to get the value of the span element with testid using react testing library?
- React warning: contains an input of type hidden with value and default value - how to fix?
More Query from same tag
- this.state.elements.map is not a function
- How to post a url
- How to open/close antd Submenu programatically
- Internal server error 500 react post to firebase
- Object's data missing when passing to Meteor.call
- webpack 5 module.hot is undefined
- How to reset the form and login error message in reactjs
- Is it possible to pass an id/ string to an onFocus event?
- React and jquery-ui/ui/widgets/sortable: Child component not reorder as expect
- BreakPoints with gridlisttiles
- Call function in other child component when mouse up
- Correct way to use button navigation in react
- React js a problem about updating the state value
- react-table not rendering data in the initial load and after page refresh
- Django Rest Framework + React rest hooks CORS error
- React JS - Passing functions for child components
- How to modify Gatsby Starter Lightbox to query specific image directories?
- How can I set the proper scroll position my reactcomponent?
- Gatsby i18next plugin No codeFrame could be generated
- how to filter array object using object property
- useSelector is not giving the value after useDispatch
- How to get values from child components in React
- React useEffect dependent on value which is initialized after api has been called
- Stripe not initialized
- React and react-dom still being bundled from the rollup bundler
- Ist there a way to pass data from child to parent using Hooks?
- Disable react-router Link in react
- How to add css file in component in Next js
- How to redirect to a page after login while send a token as a hander to middleware both using express
- How can I add state values to a default input value in React