简体   繁体   中英

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

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.

You need to create a validator function on your handleChange.

See: How to set input alphanumeric value format in input field reactjs?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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