regexp rule not validated

Created on 13 October 2014, over 10 years ago
Updated 25 January 2025, 5 days ago

I try to apply a regex fapi validator on a text field, (used as an email address), to avoid noreply addresses.
But this not work:

$form['mail'] = array(
      '#type' => 'textfield',
      '#placeholder' => t('Email'),
      '#maxlength' => 255,
      '#required' => TRUE,
      '#rules' => array(
        array('rule' => 'regexp[/(^noreply)/]', 'error' => t('Please, use a valid email address.')),
      ),
    );

I am finally successfully using as an alternative the form validate:

function MYMODULE_form_validate($form, &$form_state) {
  if (!valid_email_address($form_state['values']['mail'])) {
    form_set_error('mail', t('You must enter a valid email.'));
  }
  if (preg_match(('/^noreply|^no-reply/i'), ($form_state['values']['mail']))) {
    form_set_error('mail', t('You must enter a valid reply email.'));
  }
}

I tried several regexp combination with no success, I guess it could be a bug, or my misunderstanding of the api.

πŸ› Bug report
Status

Closed: outdated

Version

2.2

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain pedrosp Madrid, Spain

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡¦Ukraine AstonVictor

    I'm closing it because the issue was created a long time ago without any further steps.

    if you still need it then raise a new one.
    thanks

Production build 0.71.5 2024