Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email Validation

Status
Not open for further replies.

pip12345

Technical User
Joined
Sep 2, 2005
Messages
4
Location
FR
I am new to Java, please can someone confirm that the following would work:

//Start of Java
/*
* Checks for invalid characters
* in email addresses
*/
public class EmailValidation {

public static boolean isEmailValid(String email){
boolean retval=false;
String emailPattern = "^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$";
retval= email.matches(emailPattern);

}
//End of Java

This would be really appreciated... I am going to be calling this in some XML and if an incorrect email has been entered, a statement from the xml will appear to the user.

thanks
Pip
 
well it doesn't compile for a kick off ... so no, it won't work !

The way to test code like this (once you have it compiling) is to think of as many stupid combinations or carp that someone could enter into your "email" variable - including the things that you think no-one ever would (control characters, escape chars, and various combinations of those).

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Have you any idea why it will not compile?
Any comments would be really appreciated.
thanks
Pip
 
You may have to import some classes
 
If you compile it, then you will see :)

[And no, its not imports]

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Don't forget that you need to put the class on a package

package something
 
Compile it and post your errors if you can't resolve them. Here you have some hints:

1.- You cannot happily use \
2.- A boolean function must return a boolean.

Cheers,
Dian
 
4345487 :

Don't forget that you need to put the class on a package

That's incorrect. Standalone classes do not need to be packaged.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top