public static function GroupChannelWidget::validate in Rocket.Chat 8.2
Validate the channel name field.
Parameters
$element:
\Drupal\Core\Form\FormStateInterface $form_state:
Return value
bool
File
- modules/
rocket_chat_group/ src/ Plugin/ Field/ FieldWidget/ GroupChannelWidget.php, line 111
Class
- GroupChannelWidget
- Class GroupChannelWidget
Namespace
Drupal\rocket_chat_group\Plugin\Field\FieldWidgetCode
public static function validate($element, FormStateInterface $form_state) {
$value = $element['#value'];
if (strlen($value) == 0) {
$form_state
->setValueForElement($element, '');
Drupal::messenger()
->addWarning(t("An empty value will disable Chat."), FALSE);
return TRUE;
}
if (!preg_match('/^[a-zA-Z]+[a-zA-Z0-9\\-_.!?()>\\\\+=\\[\\]{};:|\\t &$%^\'\\",~`]*$/', $value)) {
$form_state
->setError($element, t("Enter a Valid Channel name.<br> Valid Channel names start with a letter[a-z,A-Z] and do than contain only characters of the following set:<br>[a-zA-Z0-9-_.!?()>\\+=\\;:|[:tab:][:space:]&\$%^'\", ~`]"));
return FALSE;
}
return TRUE;
}