473,387 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help me check String -- mail address

in java I want to check A String as mail
I have done but i think itisn't true
Oct 3 '07 #1
17 1747
dmjpro
2,476 2GB
in java I want to check A String as mail
I have done but i think itisn't true
Post your Code what you tried so far with Code Tags.
One more thing do you know regular expression.
Have a look at this and try it using Regular Expression.
Mind it, Reg Exp. supported in J2SE-1.5 :-)

Kind regards,
Dmjpro.
Oct 3 '07 #2
Post your Code what you tried so far with Code Tags.
One more thing do you know regular expression.
Have a look at this and try it using Regular Expression.
Mind it, Reg Exp. supported in J2SE-1.5 :-)

Kind regards,
Dmjpro.
class StringDemo{
public static boolean isEmailAddress(String address) {
int dot,at;
dot = address.indexOf(".");
at = address.indexOf("@");
if( at ==-1 ||dot==-1|| address.length()< dot||(dot<at)&&) return false;
else return true;
}
public static void main( String[] arg){
System.out.println(isEmailAddress("lenguye..@"));
}


}
but if string conatin dot before @ i can't process
Oct 3 '07 #3
help me !! this probelem i think it isn't difficult to you
thanks
Oct 3 '07 #4
dmjpro
2,476 2GB
class StringDemo{
public static boolean isEmailAddress(String address) {
int dot1,at1,dot2,at2;
dot = address.indexOf(".");
at = address.indexOf("@");
if( at ==-1 ||dot==-1|| address.length()< dot||(dot<at)&&) return false;
else return true;
}
public static void main( String[] arg){
System.out.println(isEmailAddress("lenguye..@"));
}


}
but if string conatin dot before @ i can't process

Please use Code Tags.
So you are checking that only one occurrence of "." and "@".
Right :-)
It will be possible with Regular Expression but I am not familiar with Regular Expression, so I am doing it using plain Java Code.

Expand|Select|Wrap|Line Numbers
  1. public static  boolean   isEmailAddress(String address) {
  2. int dot,at;
  3. dot1 = address.indexOf(".");
  4. at1 =     address.indexOf("@");
  5. dot2 = address.lastIndexOf(".");
  6. at2 =     address.lastIndexOf("@");
  7. if(dot1!=-1 && at1 !=-1 && dot1 != dot2 && at1 != at2) return true;
  8. else return false;
  9. }
  10.  
Enjoy the code :-)
Good Luck !

Kind regards,
Dmjpro.
Oct 3 '07 #5
r035198x
13,262 8TB
Always use a regular expression for this stuff, something like
Expand|Select|Wrap|Line Numbers
  1. Pattern.compile(".+@.+\\.[a-z]+");
Oct 3 '07 #6
Please use Code Tags.
So you are checking that only one occurrence of "." and "@".
Right :-)
It will be possible with Regular Expression but I am not familiar with Regular Expression, so I am doing it using plain Java Code.

Expand|Select|Wrap|Line Numbers
  1. public static  boolean   isEmailAddress(String address) {
  2. int dot,at;
  3. dot1 = address.indexOf(".");
  4. at1 =     address.indexOf("@");
  5. dot2 = address.lastIndexOf(".");
  6. at2 =     address.lastIndexOf("@");
  7. if(dot1!=-1 && at1 !=-1 && dot1 != dot2 && at1 != at2) return true;
  8. else return false;
  9. }
  10.  
Enjoy the code :-)
Good Luck !

Kind regards,
Dmjpro.
that code above it can't run true
it's true when i input 2 dot and 2 @
Oct 3 '07 #7
dmjpro
2,476 2GB
that code above it can't run true
it's true when i input 2 dot and 2 @
Sorry I did a great mistake, :-(
Can't you change it yourself buddy, please apply your own brain when you have it :-)
Anyway !

Expand|Select|Wrap|Line Numbers
  1. if(dot1!=-1 && at1 !=-1 && dot1 == dot2 && at1 == at2) return true
  2. else return false;
  3.  
Kind regards,
Dmjpro.
Oct 3 '07 #8
that code above it can't run true
it's true when i input 2 dot and 2 @
you can check this code
public boolean isEmailAddress(String address) {
int At,Dot,DO;
At = address.indexOf("@",0);
Dot = address.indexOf(".",At+1);
if(address.length() > Dot) DO = 1;
else = -1;

if((At == -1) || (Dot == -1) || (Do == -1)) return false;
return true;
}
Oct 3 '07 #9
dmjpro
2,476 2GB
you can check this code
public boolean isEmailAddress(String address) {
int At,Dot,DO;
At = address.indexOf("@",0);
Dot = address.indexOf(".",At+1);
if(address.length() > Dot) DO = 1;
else = -1;

if((At == -1) || (Dot == -1) || (Do == -1)) return false;
return true;
}
What about my code?

Kind regards,
Dmjpro.
Oct 3 '07 #10
r035198x
13,262 8TB
Throw all that stuff away and use regular expressions. They are the right tool for the job.

P.S If you guys really like to learn Java, you have to first learn to take advice.
Oct 3 '07 #11
dmjpro
2,476 2GB
Throw all that stuff away and use regular expressions. They are the right tool for the job.

P.S If you guys really like to learn Java, you have to first learn to take advice.
Yeah it's right, but I think if it is done then he or she can learn the logic development.
But finally he or she will do that using Reg Exp.
Don't mind Admin, if I told anything wrong.

Kind regards,
Dmjpro.
Oct 3 '07 #12
JosAH
11,448 Expert 8TB
Always use a regular expression for this stuff, something like
Expand|Select|Wrap|Line Numbers
  1. Pattern.compile(".+@.+\\.[a-z]+");
That thing accepts two or more dots next to each other and multiple at-signs
all over the place. I'm afraid the RE is more complicated than that:

1) [^\.@]+

accepts anything without dots and at-signs, so

2) [^\.@]+(\.[\.@]+)*

accepts sequences of 1) separated by a single dot. This little beast accepts
all stuff to the left of the at-sign in a (potential) email address.

The part to the right of the at-sign is similar to 2) but there's a top level domain
name as the rightmost part:

3) [^\.@]+(\.[\.@]+)*\\.[a-z]+

Now 2) and 3) together, separated by an at-sign accepts an email address:

[^\.@]+(\.[\.@]+)*@[^\.@]+(\.[\.@]+)*\\.[a-z]+

*yuck* ;-)

kind regards,

Jos
Oct 3 '07 #13
r035198x
13,262 8TB
That thing accepts two or more dots next to each other and multiple at-signs
all over the place. I'm afraid the RE is more complicated than that:

1) [^\.@]+

accepts anything without dots and at-signs, so

2) [^\.@]+(\.[\.@]+)*

accepts sequences of 1) separated by a single dot. This little beast accepts
all stuff to the left of the at-sign in a (potential) email address.

The part to the right of the at-sign is similar to 2) but there's a top level domain
name as the rightmost part:

3) [^\.@]+(\.[\.@]+)*\\.[a-z]+

Now 2) and 3) together, separated by an at-sign accepts an email address:

[^\.@]+(\.[\.@]+)*@[^\.@]+(\.[\.@]+)*\\.[a-z]+

*yuck* ;-)

kind regards,

Jos
I just plugged that from devx and never bothered to check it.

There's another way of doing it in parts doesn't look cleaner as well (but regexs are not always clean anyway).

So you did a match by eliminating the illegal characters, the OP doesn't want to use them anyway ...
Oct 3 '07 #14
JosAH
11,448 Expert 8TB
I just plugged that from devx and never bothered to check it.

There's another way of doing it in parts doesn't look cleaner as well (but regexs are not always clean anyway).

So you did a match by eliminating the illegal characters, the OP doesn't want to use them anyway ...
Ah, yes, if you assume that the email address is correct anyway, your RE:
".+@.+\\.[a-z]+" works fine of course. There's an old saying in the compiler
'world' that goes: "any fool can write a compiler for a perfect user" (no insult
intended).

kind regards,

Jos@.....@@.@.@.@....foo
Oct 3 '07 #15
i understand that but I can't process email like sadgasdaga@gsadg.
i use address.length() but no - help me again
Oct 3 '07 #16
That thing accepts two or more dots next to each other and multiple at-signs
all over the place. I'm afraid the RE is more complicated than that:

1) [^\.@]+

accepts anything without dots and at-signs, so

2) [^\.@]+(\.[\.@]+)*

accepts sequences of 1) separated by a single dot. This little beast accepts
all stuff to the left of the at-sign in a (potential) email address.

The part to the right of the at-sign is similar to 2) but there's a top level domain
name as the rightmost part:

3) [^\.@]+(\.[\.@]+)*\\.[a-z]+

Now 2) and 3) together, separated by an at-sign accepts an email address:

[^\.@]+(\.[\.@]+)*@[^\.@]+(\.[\.@]+)*\\.[a-z]+

*yuck* ;-)

kind regards,

Jos
i'm sorry evrybody - because i have never used regular expression and the first i do about mail
Oct 3 '07 #17
r035198x
13,262 8TB
i understand that but I can't process email like sadgasdaga@gsadg.
i use address.length() but no - help me again
Are you using regex for this yet?
Oct 3 '07 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: mcp6453 | last post by:
I am trying to use Jack's FormMail script (http://www.dtheatre.com/scripts/formmail). Since I'm brand new at PHP and not very good at HTML, I have an easy question, which I will narrow down. When...
17
by: Sue | last post by:
<html> Is there someone here that can help me validate the period as the fourth from the last character in an email address. There is other information and validation on the form I have to do but...
9
by: YZK | last post by:
Hello. I'm not a Web developer, just a user, and I think I may have somehow messed myself up majorly. I'm not quite sure how. Right now, javascript used by websites I go to either does not work at...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
2
by: Mike Brearley | last post by:
I need to write a script that will check a catch-all mailbox (pop3) and send a non delivery report back to the sender of the email. Background info: I have a domain hosted on a site that offers...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
11
by: cybervigilante | last post by:
I can't seem to change the include path on my local winmachine no matter what I do. It comes up as includ_path .;C:\php5\pear in phpinfo() but there is no such file. I installed the WAMP package...
1
by: CodeSeeker | last post by:
I have an application, which uses pop3 to read the messages from the mailbox, and it has been working fine for so many year. We recently have started changing this application to use java mail IMAP 4...
1
by: zhang | last post by:
what's the problem?? Remote_Addr = "hotmail.com" sFrom = "<makefriend8@" & Remote_Addr + ">" Dim oConnection As New TcpClient() Try oConnection.SendTimeout = 3000 ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.