0

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

1

1 Answer 1

0

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?

Sign up to request clarification or add additional context in comments.

2 Comments

Yes it would have but the problem come here is I am using Formick which is handling the handle change on onChange={handlEChange} so will it work in runtime without sending the data to formick and before only vaildating it with regex @Almaju
You can wrap the function from formik, there is no problem to do that. Something like onChange={(value) => handleChange(validate(value))}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.