[英]I want to accept only 1-24 in the input field and disable all other buttons. how is it possible
This is my input field and I want to accept only 1-24 and disable all other keys.这是我的输入字段,我只想接受 1-24 并禁用所有其他键。 How can this be achieved in react.
如何在反应中实现这一点。
<TextFieldCustom
placeholder="Enter checkin hours"
value={e.target.value}
onChange={onChangeHandler}
maxLength={3}
type=number
onKeyDown={onKeyDown}
/>
here is the change handler of your case without specifying type="number" :这是您的案例的更改处理程序,但未指定 type="number" :
const [text, setText] = useState('');
const changeHandler = (e: any) => {
const val = e.target.value;
if ((val >=1 && val <= 24) || val === '') {
setText(val);
}
};
return (
<TextFieldCustom
placeholder="Enter checkin hours"
value={text}
onChange={changeHandler}
onKeyDown={onKeyDown}
/>
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.