wood burning stoves 2.0*
The moose likes Java in General and the fly likes indexof chek Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "indexof chek" Watch "indexof chek" New topic
Author

indexof chek

Jahar Heard
Greenhorn

Joined: Jan 09, 2010
Posts: 20
Hi!

I'm trying to see if the email that is being typed is valid, so I'm using a indexOf and the question is how to find if the method indexOf has found the typed character in it ?

For example .

email.indexOf('@', 1);
How can I find, if the (email) string contains @, if not to do something, and if doest to do something else .


If you have Ideas for another way to find valid email, please tell
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

check this may help you.


Life is easy because we write the source code.....
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14274
    
  21

Lookup the documentation of the method indexOf() in class String. It tells you exactly what it returns if the string does not contain the character you're looking for.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Jahar Heard
Greenhorn

Joined: Jan 09, 2010
Posts: 20
Thanks to both, I will see the documentation ..

I tried with the tutorial you gave me, but the Pattern, does not make it run ..



But the mail doesn't post . No errors, just when I post it, nothing happen .
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14274
    
  21

The original code that Pramod posted a link to contains a regular expression like this:

But you changed it to this:

That will not work. You're not supposed to change the regular expression. Use the code exactly like it is on that page:

Ofcourse, in the string email, put the e-mail address that you are trying to verify.
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

Tutorial just check whether email address is valid or not.
the mail doesn't post . No errors, just when I post it, nothing happen

It means there is problem in your code which send mail.
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

Oh I had not look up that Vladislav made changes in code. Jesper is correct change the regular expression as

Thanks Jesper.
Jahar Heard
Greenhorn

Joined: Jan 09, 2010
Posts: 20
Thanks

It worked, the index and the pattern, so .. thanks
Anyway, the pattern is more useful then the index way so I will use it
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: indexof chek