[英]Material Ui Textfield Pattern matching
Hi I am new to material ui I trying to textField only allows number,using patter but not working and also tried with number type it working But need with pattern matching only嗨,我是材料 ui 的新手,我尝试 textField 只允许数字,使用模式但不工作,还尝试使用数字类型它工作但只需要模式匹配
Thanks for Help感谢帮助
<TextField
name="salary"
value={salary}
variant="outlined"
size="small"
fullWidth
autoComplete="off"
pattern="[0-9]+"
/>
it just makes an error for input:它只是输入错误:
import React from "react";
import ReactDOM from "react-dom";
import TextField from "@material-ui/core/TextField";
import { withStyles } from "@material-ui/core/styles";
const styles = {
input: {
"&:invalid": {
border: "red solid 2px"
}
}
};
function App({ classes }) {
return (
<TextField
inputProps={{ className: classes.input, pattern: "[0-9]{1,15}" }}
/>
);
}
const StyledApp = withStyles(styles)(App);
const rootElement = document.getElementById("root");
ReactDOM.render(<StyledApp />, rootElement);
<TextField
name="salary"
value={salary}
variant="outlined"
size="small"
fullWidth
autoComplete="off"
type="number" // this is the trick
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.