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 :-)
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.prin tln(isEmailAddr ess("lenguye..@ "));
}
}
but if string conatin dot before @ i can't process
class StringDemo{
public static boolean isEmailAddress( String address) {
int dot1,at1,dot2,a t2;
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.prin tln(isEmailAddr ess("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.
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.
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.leng th() > Dot) DO = 1;
else = -1;
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.leng th() > Dot) DO = 1;
else = -1;
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.
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).
Comment