Verifying Email Address

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

liquedus
php-forum Active User
php-forum Active User
Posts: 266
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada
Contact:

Verifying Email Address

Postby liquedus » Wed May 21, 2003 6:32 am

I am just curious as to what is the best method for verifying and email address, a regex or some other way by using string functions?

or would it be better to do is client side using JS? (I already have the function for it)

User avatar
bezmond
Moderator
Moderator
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK
Contact:

Postby bezmond » Wed May 21, 2003 7:39 am

what do you mean by verify?
You mean check it is a valid email address?

Andrew

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Clientside

Postby ruturajv » Wed May 21, 2003 9:20 am

Definately a JScript client side function is faster and effective

liquedus
php-forum Active User
php-forum Active User
Posts: 266
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada
Contact:

Postby liquedus » Wed May 21, 2003 9:47 am

andrew: yes, sorry about not making it clear in my original post

hmm, thats one for client side...

User avatar
bezmond
Moderator
Moderator
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK
Contact:

Postby bezmond » Wed May 21, 2003 10:04 am

if you wanted to check the email address was real, you could use an inactive tag on an account, then mail that email account using mail(), getting them to click a link to verify their email address is correct...

Andrew

liquedus
php-forum Active User
php-forum Active User
Posts: 266
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada
Contact:

Postby liquedus » Wed May 21, 2003 11:02 am

whoa, not verify to that point :)

no just make sure that the structure is correct for an email address.

ex:

valid: r@r.com
not: r@.com

just that kind of verification, i think i will go client side.... just wanted to know the best way to do it in php

User avatar
gorshing
New php-forum User
New php-forum User
Posts: 12
Joined: Thu Dec 05, 2002 5:56 pm
Location: Oklahoma, US
Contact:

Postby gorshing » Wed May 21, 2003 1:45 pm

Code: Select all

function valemail(field)
{
   if((field.value.indexOf("@")==-1) && (field.value != ""))
   {
      alert("Please enter a valid email address");
      field.focus();
   }
}


This is what I use in JavaScript ... but it doesn't test everything possible. I guess you could build on that ;)

liquedus
php-forum Active User
php-forum Active User
Posts: 266
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada
Contact:

Postby liquedus » Thu May 22, 2003 6:08 am

gorshing: thanks, I already have a function that will test for most things in JS, I was wondering what the best way was in PHP

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Postby WiZARD » Fri May 23, 2003 4:38 am

hi liquedus!
i'm use that function in php, easy and flaxyble:

Code: Select all

function is_email($string_value)
{
 $pattern = "^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|
bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck
|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|
ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|
gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it
|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma
|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|
mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|
pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|
sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|
tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|
ye|yt|yu|za|zm|zw)
|
(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$";
 if(eregi($pattern, $string_value, $regs)) return true;
 elseif(gethostbyname($regs[2]) == $regs[2]) return false;
 else  return false;
}

liquedus
php-forum Active User
php-forum Active User
Posts: 266
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada
Contact:

Postby liquedus » Fri May 23, 2003 7:43 am

cool, thanks wizard, thats exactly what i was looking for

User avatar
mike
New php-forum User
New php-forum User
Posts: 73
Joined: Sun May 04, 2003 4:26 am
Location: Athens
Contact:

Postby mike » Fri May 23, 2003 6:14 pm

There are 3 ways checking for a valid email address:

1. sending an activation link and user should click on it to verify existance of email

2. sending a HELO message to email account and get a responce through socket functions. (this is the best one)

3. verifying existance of MX Records on the domain an email account is on

All other methods are used to check correct syntax of an email address (eg. something@domain.xxx)

liquedus
php-forum Active User
php-forum Active User
Posts: 266
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada
Contact:

Postby liquedus » Sat May 24, 2003 7:03 am

thanks but wizards answer is what i was looking for

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Postby WiZARD » Sat May 24, 2003 7:21 am

liquedus wrote:thanks but wizards answer is what i was looking for

don't mention!


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 4 guests

cron