Restrict user to add duplicate number on registration page

Created on 5 May 2023, about 1 year ago

Problem/Motivation

Need to add phone verification validation on registration page, while user creating a account on the site.
if he has already used then we need to show a message to the user "This number is already in use and cannot be assigned to more than one account"

Steps to reproduce

Proposed resolution

add form alter in twilio.module file.
$form['actions']['submit']['#validate'][] = 'twilio_register_validate';

/**
 * Custom validation function for phone numbers during registration.
 */
function twilio_register_validate($form, FormStateInterface $form_state) {
  $value = $form_state->getValues();

  $num_verify = \Drupal::service('twilio.sms')->twilio_verify_number($value['number']);
  
 
  // Something has been entered but is non numeric.
  if (!is_numeric($value['number'])) {
    $form_state->setErrorByName('number', t('You must enter a valid phone number'));
    return false;
  }
  
  if ($num_verify) {
    $form_state->setErrorByName('number', t('This number is already in use and cannot be assigned to more than one account'));
  
  return false;
  }
  
  return true;
}
✨ Feature request
Status

Fixed

Component

Code

Created by

🇮🇳India shashank5563 New Delhi

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

Comments & Activities

Production build 0.69.0 2024