954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Validating Email Addresses - A little extra help!

Hi guys....newbie on the forums here :)

I have developed a php form processor for a project i am working on. I am trying to validate the email address, however i want to add 1 more check the the default script. At the moment i have the following:

function if_email($staff)
{
  //Check the valididty of the email address entered
  if (ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $address))
    return true;
  else 
    return false;
}


Which I have taken from a PHP book i am working with. My question is as follows:

The textbox that the $staff variable is linked to has the text "[USERNAME]@landau-forte.org.uk" pre-defined in it. Staff must change the username section for their own. Can someone tell me how to check...if the email has the phrase '[USERNAME]' in it then return it as an error?

Thanks for your help,

JameZ ;)

nikez
Newbie Poster
13 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

why not drop everything after the @, add that on using php after they click submit or whatever, then just verify the [USERNAME] box with a if $x = statement?

HawkeVIPER
Junior Poster in Training
72 posts since Jan 2005
Reputation Points: 10
Solved Threads: 4
 

ok I think this was what u asked. ..
you wanted a script that validating some e-mail address that *MUST* have a domain of landau-forte.org.uk
if i am correct then this should do the job

function if_email($email)
{
  //Check to make sure this is a valid email address on landau-forte.org.uk
  if (ereg('^[a-zA-Z0-9_\.\-]+@landau-forte.org.uk$', $email))
    return true;
  else 
    return false;
}
paradox814
Posting Whiz
351 posts since Oct 2004
Reputation Points: 13
Solved Threads: 4
 

ok I think this was what u asked. .. you wanted a script that validating some e-mail address that *MUST* have a domain of landau-forte.org.uk if i am correct then this should do the job

function if_email($email)
{
  //Check to make sure this is a valid email address on landau-forte.org.uk
  if (ereg('^[a-zA-Z0-9_\.\-]+@landau-forte.org.uk$', $email))
    return true;
  else 
    return false;
}

He wants a script to validate that an e-mail address HAS been entered.

I.e.

function if_email($email) {

//Define check
$bademail = '\[USERNAME\]';
//Check that [USERNAME] is not contained in e-mail field
if (ereg($bademail . '@^[\w_\.\-]$', $address))
  return false;
 else if (ereg('^[\w_\.\-]+@[\w\-]+\.[\w\-\.]+$', $address))
  return true;
 else
  return false;
}


that *should* work

HawkeVIPER
Junior Poster in Training
72 posts since Jan 2005
Reputation Points: 10
Solved Threads: 4
 

Thanks everyone for your suggestions.

Will have a mess about with what you all posted and see if i can make it work :)

Cheers,
JameZ

nikez
Newbie Poster
13 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You