I'm need to validate Alternate Login accept only integers numbers

The function _alt_login_validate works fine with these code:


// Required 
if (empty($edit['alt_login'])) {
form_set_error('alt_login', t('Alternate Login must be required.'));
}

// Only Numbers
if(!is_numeric($alt_login)) {
form_set_error('alt_login', t('The name %name must be numbers.', array('%name' => $alt_login)));
}

But this validation code don't accept integer numbers or decimal numbers:

    if (!is_int($alt_login)) {
      form_set_error('alt_login', t('The name %name must be integer.', array('%name' => $alt_login)));
    }

What happen with this validation,

Please I need support

Thanks so much

Comments

hunmonk’s picture

Status: Active » Fixed

you're using the wrong function.

check out http://php.net/is_int -- you should find that instructive for your needs.

oemb29’s picture

I don't know why and I'm not sure, but in PHP 4 is_int("23") is a string and is_int(23) is a integer, this validation fixed the problem:

  // 0 decimal places
    if (strlen(strrchr($alt_login, "."))!=0) {
      form_set_error('alt_login', t('The name %name must be integer.', array('%name' => $alt_login)));
    }

Thanks hunmonk

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

summit’s picture

Version: 5.x-1.7 » 6.x-1.x-dev

Looking for D6 version of the same.
greetings, Martijn