Welcome Guest, Not a member yet? Register   Sign In
Checking for specific domain in email address?
#1

[eluser]Wonder Woman[/eluser]
Hi,

I'm trying to check if a user is registering with the correct email address, it must be of a specific domain... for example [email protected]

I found a script on the web and tried changing it with no luck, can you help me please?

Code:
function _valid_domain($str)
{
list($mailbox, $domain) = split('@', $str);
if (!(checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A'))) {
  $this->form_validation->set_message(__FUNCTION__, "Domain "{$domain}" not found.");
  echo $domain;
  return FALSE;
} else {
  if($domain == "mywebsite.com"){
   return TRUE;
  } else {
   return FALSE;
  }
}
}

Code:
$this->form_validation->set_rules('email', 'Email address', 'trim|required|xss_clean|valid_email|callback__valid_domain');
#2

[eluser]Glazz[/eluser]
Something like:

Code:
$email = "[email protected]";
list($user, $domain) = explode('@', $email);
echo $domain;
#3

[eluser]Wonder Woman[/eluser]
Yes that would work but I want it on a callback function and it just isn't working Sad

Code:
$this->form_validation->set_rules('email', 'Email address', 'trim|required|xss_clean|valid_email|callback_valid_domain');
#4

[eluser]Glazz[/eluser]
Is your callback function getting called ?
Try placing an echo inside the function and see if it shows up, if not, the callback is not working.

Edit:

Your function needs to look something like:
Code:
function _valid_domain($email)
{
list($user, $domain) = explode('@', $email);
if ( $domain == 'mywebsite.com')
{
  return true;
} else {
  return false;
}
}
#5

[eluser]Wonder Woman[/eluser]
I have fixed it thanks, didn't realise it had to be in the same Controller. Thanks Smile
#6

[eluser]Glazz[/eluser]
Glad you figured it out =)

- g l a z z




Theme © iAndrew 2016 - Forum software by © MyBB