F
Filament10mo ago
WEBMAS

How to enter only letters and numbers in TextInput?

How to enter only letters and numbers? Something like the regular expression [a-zA-Z0-9_] TextInput::make('telegram') ->label(__('page.profile.fields.telegram')) ->prefix('@') ->minLength(5) ->maxLength(32),
8 Replies
WEBMAS
WEBMASOP10mo ago
Help please 😔
awcodes
awcodes10mo ago
->extraInputAttributes([‘pattern’ => ‘regrex’]) https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/pattern
MDN Web Docs
HTML attribute: pattern - HTML: HyperText Markup Language | MDN
The pattern attribute specifies a regular expression the form control's value should match. If a non-null value doesn't conform to the constraints set by the pattern value, the ValidityState object's read-only patternMismatch property will be true.
awcodes
awcodes10mo ago
Or possibly use a mask()
WEBMAS
WEBMASOP10mo ago
Thank you. I tried to do it through a mask, but I never found instructions on how to make only numbers and letters. Of course, I would like to do it through a mask. But how?
awcodes
awcodes10mo ago
Probably better to do it with the pattern. Just let the browser handle it.
WEBMAS
WEBMASOP10mo ago
If you do ->extraInputAttributes([‘pattern’ => ‘regrex’]), then I think the backend validation will not work. If you remove this attribute in the browser through code viewing tools, the server will accept incorrect data.
sandofgods
sandofgods10mo ago
you can't do that with ->mask, it's using alpine.js mask (https://alpinejs.dev/plugins/mask#x-mask) and it's handling Any, Only Alpha, Only Numeric. But, you cant use this one https://filamentphp.com/docs/3.x/forms/validation#alpha-numeric
Mask — Alpine.js
Automatically format text fields as users type
WEBMAS
WEBMASOP10mo ago
This Field::make('name')->alphaDash() looks like what I need. Thank you. I'll try it tomorrow.
Want results from more Discord servers?
Add your server