In my application, I have an antd input. I need to put here some type of mask like 123-456-789-123. So I'm trying to use Regex. But nothing works for me.
Here is live example https://codesandbox.io/s/basic-antd-5-8-3-forked-ds885j?file=/demo.js:0-543
And here is the code:
import React, { useState } from "react";
import "./index.css";
import { InputNumber } from "antd";
const App = () => {
const [value, setValue] = useState(1);
const onChange = (value) => {
const parsedValue = value
.toString()
.replace(/^([0-9]{3})([0-9]{3})([0-9]{3})([0-9])$/, "$1-$2-$3-$4");
// const parsedValue = value.toString().replace(/(.{3})/g, "$1-");
console.log(parsedValue);
setValue(parsedValue);
};
return <InputNumber value={value} onChange={onChange} />;
};
export default App;
.replace(/^([0-9]{3})([0-9]{3})([0-9]{3})([0-9])$/, "$1-$2-$3-$4");
this expression works fine, but only after 10 symbols are written in the input. But I want to find a solution to insert hypnonen immediately.