Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

indexof chek

 
Jahar Heard
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check this may help you.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15436
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jahar Heard
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15436
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic