Not allowing textarea to proceed if enter or space is entered
- Pavel Kravčík
- Member | 1195
You can try custom calback $form->onValidate[] = function()
or something like this:
$form->addText('nick', 'Username')
->addRule([$this, 'isUsernameAvailable'], 'Go home, this nickname is already taken');
//...
public function isUsernameAvaible()
{
public function isUsernameAvailable($name)
{
//Your logic return Boolean
}
}
- David Matějka
- Moderator | 6445
You can use a PATTERN validator, e.g:
->addRule(Form::PATTERN, 'error message', '[^\s]+')
- McLel
- Member | 12
David Matějka wrote:
You can use a PATTERN validator, e.g:
->addRule(Form::PATTERN, 'error message', '[^\s]+')
Thank you for the response. I should've made my question more clear:
I want error message to pop if user tries to enter Space(s) or Enter(s), but I want the textarea to proceed if he enters normal sentence(s).
In other words, if user enters just Space(s) or Enter(s), validation should consider textarea to be empty.
Last edited by McLel (2015-09-30 15:21)
- McLel
- Member | 12
David Matějka wrote:
Oh, sorry. this regexp should work:
.*[^\s].*
Great, I believe we are getting close :-). It returns error if spaces or new lines are entered and proceeds if sentences are entered. I need just one more thing.
I can now send “Hello world” but cannot send
Hello world
Hello there
How can I achieve this?
- David Matějka
- Moderator | 6445
Try negative validator using ~
:
->addRule(~Form::PATTERN, '...', '[\s]+')