Material-ui: [TextField] "pattern" attribute

Created on 8 Nov 2017  ·  6Comments  ·  Source: mui-org/material-ui

  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

An input text field can have a pattern attribute containing a regex string, which the browser natively uses for validation (HTML5 spec).

Current Behavior

Currently, passing pattern to TextField does not transmit it to the underlying input, making native regex validation impossible.

Steps to Reproduce (for bugs)

https://codesandbox.io/s/wy56937zy5

Your Environment

| Tech | Version |
|--------------|---------|
| Material-UI |1.0.0-beta.20|
| React |16.0.0|
| browser |Chrome|

Most helpful comment

My bad! The inputProps prop can be used to transmit props to the input:

https://codesandbox.io/s/wy56937zy5

All 6 comments

My bad! The inputProps prop can be used to transmit props to the input:

https://codesandbox.io/s/wy56937zy5

@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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  ·  3Comments

ryanflorence picture ryanflorence  ·  3Comments

iamzhouyi picture iamzhouyi  ·  3Comments

reflog picture reflog  ·  3Comments

chris-hinds picture chris-hinds  ·  3Comments