简体   繁体   English

Material UI TextField 正则表达式

[英]Material UI TextField Regex

I need two textbox from TextField from MaterialUI one that can only enter alphabets(small or capital can also include spaces {Example: Risha Raj} as first textfield) and other one is also except only alphabets (small or capital) but with maxLength with only 3我需要来自 MaterialUI 的 TextField 的两个文本框,一个只能输入字母(小号或大写字母也可以包含空格 {Example: Risha Raj} 作为第一个文本字段),另一个也只有字母表(小号或大写字母)除外,但 maxLength 只有3个

so I did the following所以我做了以下

           <TextField
            id='Product Name'
            label='Enter Student  Name'
            name='sname'
            value={values.sname}
            onChange={handleChange}
            error={errors.sname}
          />
            <TextField
            id='section'
            label='Enter Class Section'
            name='ccode'
            inputProps={{maxLength:3}}
            value={values.ccode}
            onChange={handleChange}
            error={errors.ccode}
          />

I am able to restrict the length but unable to do the alphabets我可以限制长度但不能做字母

This has nothing to do with Material UI.这与 Material UI 无关。

You need to create a validator function on your handleChange.您需要在 handleChange 上创建一个验证器 function。

See: How to set input alphanumeric value format in input field reactjs?请参阅: 如何在输入字段 reactjs 中设置输入字母数字值格式?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM