Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Space checking in a String

 
Brian
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to check for space inside a String value? I am validating email address in my application and need to make sure I have a some what valid email address.

Thanks
 
john guthrie
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think this is in the wrong group, but String.indexOf is your answer
 
Salman Khattak
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i would use regular expressions to check valid email addresses.
regexlib.com has good regex
 
Java Green
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an implemetation provided in struts validator frame work to check whether it is email or not. There is an "isEmail()" method available in org.apache.commons.validator.GenericValidator class which is available in commons-validator.jar, can be downloadable from struts.apache.org
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Is there a way to check for space inside a String value? I am validating email address in my application and need to make sure I have a some what valid email address

Assuming we are talking about addresses for SMTP, valid SMTP email addresses can have spaces in them.

Also the class InternetAddress packaged with JavaMail will validate an address as part of its constructor, unless you tell it otherwise. So if you are eventually using the address to send mail, then this is a perhaps a more sensible route than including extra 3rd party dependancies.
[ November 23, 2004: Message edited by: Paul Sturrock ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Brian"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Java Green"-
You have been asked 7 times already to adjust your displayed name to meet the

JavaRanch Naming Policy.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic