Input mask

Is it possible to use input masking with regex? And if yes, how can I do this?
3 Replies
Vp
Vp2y ago
Filament
Fields - Form Builder - Filament
The elegant TALL stack form builder for Laravel artisans.
Vp
Vp2y ago
or like this
TextInput::configureUsing(function (TextInput $component): void {
$component->telRegex('/^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\.\/0-9]*$/');
});
TextInput::configureUsing(function (TextInput $component): void {
$component->telRegex('/^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\.\/0-9]*$/');
});
DianaMujoiu
DianaMujoiuOP2y ago
I tried with pattern like this
TextInput::make('name')
->lazy()
->mask(fn (TextInput\Mask $mask) => $mask
->pattern('/^[a-zA-Z0-9]+$/')
)
TextInput::make('name')
->lazy()
->mask(fn (TextInput\Mask $mask) => $mask
->pattern('/^[a-zA-Z0-9]+$/')
)
but it's not working as I want. I need for example to let the user typing only letters and numbers, not special characters I got this error 'Filament\Forms\ComponentContainer::Filament\Forms\Concerns{closure}(): Argument #1 ($component) must be of type Filament\Forms\Components\Component, null given' with this code
TextInput::configureUsing(function (TextInput $component): void {
$component->telRegex('/^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\.\/0-9]*$/');
});
TextInput::configureUsing(function (TextInput $component): void {
$component->telRegex('/^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\.\/0-9]*$/');
});
SOLVED
TextInput::make('name')
->lazy()
->mask(fn (Forms\Components\TextInput\Mask $mask) => $mask
->pattern('{{ /^[a-z0-9-]*$/ }}')
)
TextInput::make('name')
->lazy()
->mask(fn (Forms\Components\TextInput\Mask $mask) => $mask
->pattern('{{ /^[a-z0-9-]*$/ }}')
)
Want results from more Discord servers?
Add your server