Really like the direction this module is taking and have been following its progress.

With the recent commit of Twilio as an SMS plugin, I've been keen to test this. I am not based in the US and when I attempt to set the value of the Mobile number, it return an error: "Number does not match expected patterns". I've tried various formats of an acceptable mobile number in South Africa and for that matter, other territories. I think the validation of this number is too restrictive for general use.

Without being able to enter a valid number which I have access to, I'm not able to test the implementation of this further.

Comments

coltrane’s picture

Thanks very much for your interest in this! I don't mean to only support the NAN system but current requirements only support US/CA numbers. It's briefly mentioned in the readme (http://cgit.drupalcode.org/tfa_basic/plain/README.txt) but you can validate and allow other number styles with hooks hook_tfa_basic_valid_number_alter() and hook_tfa_basic_format_number_alter(). Let me know how this works for you!

coltrane’s picture

Status: Active » Closed (works as designed)

Marking closed. Feel free to re-open if there's a problem with the existing hooks or suggestion for wider support.

johnkareoke’s picture

Category: Bug report » Support request
Status: Closed (works as designed) » Needs review
StatusFileSize
new2.4 KB

@coltrane

I've tried to create a module that implements both hook_tfa_basic_valid_number_alter() and hook_tfa_basic_format_number_alter() to validate and format the numbers for my intended audience. Bearing in mind that this is the first module I've written, I'd appreciate if you can take a glance at it below and tell me if there is something that is obviously wrong. I've tested the regex pattern and know it works, but I simply get a WSOD when I attempt to add an number for SMS.

I may simply be implementing these hooks incorrectly.

Any help is much appreciated.

tfa_rsa_number.info

name = tfa_rsa_number
description = This module allows South African Number to be used with the TFA basic plugin.
core = 7.x
dependencies = tfa, tfa_basic

tfa_rsa_number.module

<?php

function tfa_rsa_number_tfa_basic_valid_number_alter($number) {

$pattern = '~^((?:\+27|27)|0)(=72|82|73|83|74|84)(\d{7})$~';

if (preg_match($pattern, $number)) 	
	{
		$errors = array();
	}
		else 
	{
		$errors = array(t('Number does not match expected patterns.'));
	}

	$alterable = array(
    'number' => $number,
    'errors' => $errors,
	);

	drupal_alter('tfa_basic_valid_number', $errors);
  
  return $alterable['errors'];

}

function tfa_rsa_number_tfa_basic_format_number_alter($number) {

$number = str_replace(array('-', ' ', '(', ')','+'), '', $number);

 if (ctype_digit($number) && strlen($number) == 11) {
    $formatted = 'xx-xx-xxx-' . substr($number, 7);
  }
  elseif (ctype_digit($number) && strlen($number) == 10) {
    $formatted = 'xxx-xxx-' . substr($number, 6);
  }
  
 $alterable = array(
    'number' => $number,
    'formatted' => $formatted,
  );

  drupal_alter('tfa_basic_format_number', $alterable);
  return $alterable['formatted'];
  
}
klausi’s picture

StatusFileSize
new3.53 KB

The drupal_alter() hook in tfa_basic_valid_number() cannot work, because it does not pass the $alterable array, fixed that.

Then I think we should introduce a tfa_basic_sms_nanp_validate variable which allows site owners to opt out of the NANP validation. It defaults to 1, so nothing changes for existing installations, they still get NANP validated.

This is a very basic requirement for international users and I rather do a pretty small tfa_basic patch than writing a module for that.

greggles’s picture

That solution in #4 makes sense to me as an easy solution for those who don't want validation or don't want to write validation code.

  • coltrane committed fa2dc8a on 7.x-1.x authored by klausi
    Issue #2335051 by klausi: Twilio Basic plugin - Mobile number validation
    
coltrane’s picture

Status: Needs review » Fixed

@klausi, thanks for catching that alterables wasn't correctly passed in. I like this approach and tests pass so I've committed the patch in #4. Marking fixed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.