LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-04-2003, 01:37 AM   #1
painkiller6.6.6
LQ Newbie
 
Registered: Sep 2002
Posts: 7

Rep: Reputation: 0
check e-mail address


Hi, I'm doing an applet in java where I get users e-mail address. I'm trying to check if the e-mail is right written, something@something.something .Do you know how to do it?, or some webpage that can explain it?.
Thanks in advance.
 
Old 04-04-2003, 04:04 AM   #2
grub
Member
 
Registered: Mar 2003
Location: Kurnool, India.
Distribution: Redhat 9
Posts: 67

Rep: Reputation: 15
Hi painkiller, I think for solutions you have to search on any java site or java documentation.
 
Old 04-04-2003, 08:56 AM   #3
FredrikN
Member
 
Registered: Nov 2001
Location: Sweden
Distribution: GNU/Linux since -97
Posts: 149

Rep: Reputation: 15
Wait some minutes and I can write something for you.......
 
Old 04-04-2003, 09:14 AM   #4
FredrikN
Member
 
Registered: Nov 2001
Location: Sweden
Distribution: GNU/Linux since -97
Posts: 149

Rep: Reputation: 15
test@linuxquestions.org "is valid"

test@linuxquestionsorg "not valid"

test@linuxquestions@org "not valid"

test.linuxquestions@org "not valid"

test@linuxquestions.org. "not valid" (ending with a dot)

and so on......

It's not perfekt 100% but I hope it's better than nothing

Code:
import java.util.*;

public class EmailChecker
{
	
	private int countAt;
	private int countDot;
	private int countRight;
	private int pos;
	private int target;
	private String right;
	private StringTokenizer strTok;
		
	public boolean check(String adress)
	{
		
				
		for(int j = 0 ; j < adress.length() ; j++)
		{
			if(adress.charAt(j)=='@')
				countAt++;
	
			if(adress.charAt(j)=='.')
				countDot++;
				
		}
		
		if((countAt != 1) || (countDot < 1))
		{
			return false;
		}
		
		//Check so there is something before the @ and after
		
		if((adress.charAt(0) == '@') || (adress.charAt((adress.length())-1) == '@') || (adress.charAt((adress.length())-1) == '.'))
		{
			return false;
		}
		
		for(int j = 0 ; j < adress.length() ; j++)
		{
			if(adress.charAt(j)=='@')
				target = pos++;
	
			pos++;	
		}		
		
		if(target < adress.length()+1)
		{
		
			if((adress.charAt(target+1) == '.') || (adress.charAt(target+2) == '.'))
			{
				return false;
			}
		}	
		
		strTok = new StringTokenizer(adress,"@");
		
		while(strTok.hasMoreTokens())
		{
			right = strTok.nextToken();
		}
		
		//Checking for a . after @
		for(int j = 0 ; j < right.length() ; j++)
		{
			if(right.charAt(j)=='.')
				countRight++;
		}		
		
		if(countRight < 1)
		{
			return false;
		}
	
		
		if(right.length() < 3)
		{
			return false;
		}
		
			
		return true;
	}
		
	
}

Last edited by FredrikN; 04-04-2003 at 09:41 AM.
 
Old 04-08-2003, 12:32 AM   #5
mukul_joshi
LQ Newbie
 
Registered: Mar 2002
Posts: 1

Rep: Reputation: 0
Smile Email Validation

Check out this Site http://www.network-tools.com it has got a Email Validation there
 
Old 04-11-2003, 06:39 AM   #6
Shak
Member
 
Registered: May 2002
Location: Huddersfield
Distribution: Redhat (7.2, 7.3, 8.0), Debian, Slackware, Gentoo, FreeBSD
Posts: 169

Rep: Reputation: 30
I didnt do this in Java but I did it in PHP, the way that I did it was to make sure that it was valid by splitting it round the @ sign and checking both of the sections for anything invalid, I then ran the checkdns function on the domain to check that it exists.

Shak
 
Old 04-11-2003, 06:43 AM   #7
FredrikN
Member
 
Registered: Nov 2001
Location: Sweden
Distribution: GNU/Linux since -97
Posts: 149

Rep: Reputation: 15
I did something similar in PHP to a few months ago and I was also checking with DNS if the domain existed.

But in an performences point of view it's a bad idé.

It all depends on how fast you want the 'Email checking' to be
 
Old 04-11-2003, 06:51 AM   #8
Shak
Member
 
Registered: May 2002
Location: Huddersfield
Distribution: Redhat (7.2, 7.3, 8.0), Debian, Slackware, Gentoo, FreeBSD
Posts: 169

Rep: Reputation: 30
Thats a fair point, it depends what its for, if its for something really important then its worth taking the time out to do it

Shak
 
Old 04-11-2003, 06:53 AM   #9
FredrikN
Member
 
Registered: Nov 2001
Location: Sweden
Distribution: GNU/Linux since -97
Posts: 149

Rep: Reputation: 15
That's true
 
Old 06-13-2003, 02:30 AM   #10
painkiller6.6.6
LQ Newbie
 
Registered: Sep 2002
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks a lot. Sorry for answering so so late, but I had some problems, bike crash, and I wasn´t in the mood of programming, now everything is OK and I'm back.
 
Old 06-13-2003, 06:19 AM   #11
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
You can do regular expression checking the same sort of way as perl does on strings if you just want to test the syntax


stringname.match("<expression")

something you could look into I guess if you wanted.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sendmail - Check for Bad From Address? maxnix Linux - Security 3 02-15-2004 10:55 AM
how to check where ip address is coming from. hornet74 Linux - Networking 6 01-31-2004 02:44 PM
how can i check my ip address? alexii86 Linux - Newbie 8 10-09-2003 05:09 AM
how can I use sendmail to e-mail with an existing e-mail address? vofkid Linux - Newbie 0 03-14-2002 08:45 PM
How to check the IP address on a computer. LenkaNguyen Linux - Networking 5 01-28-2002 01:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration