An input
text field can have a pattern
attribute containing a regex string, which the browser natively uses for validation (HTML5 spec).
Currently, passing pattern
to TextField
does not transmit it to the underlying input
, making native regex validation impossible.
https://codesandbox.io/s/wy56937zy5
| Tech | Version |
|--------------|---------|
| Material-UI |1.0.0-beta.20|
| React |16.0.0|
| browser |Chrome|
My bad! The inputProps
prop can be used to transmit props to the input:
@verekia life saver, thanks
Does not seem to be working anymore. Can anyone test it again?
Does not seem to be working anymore. Can anyone test it again?
I guess you have not submitted the form yet. Pattern validation only occurs when you submit the form. It does not prevent you from entering an invalid value.
took me a while 🙈
✅ inputProps: {{pattern: '[a-z]'}}
❌ InputProps: {{pattern: '[a-z]'}}
@lk9100 See #11377
Most helpful comment
My bad! The
inputProps
prop can be used to transmit props to the input:https://codesandbox.io/s/wy56937zy5