check

E-Mail validation with Java and regular expressions (regex)

With a few lines of code you can check if an E-Mail address ist valid or not. The most import part ist our pattern:

String pattern = "([a-z0-9_.-]+@[a-z0-9-]+\\.[a-z]{2,6})";

import java.util.regex.*;

public class EmailCheck {

	public static void main(String[] args) {

		String eMail = "youremailyoursite.com"; 
		
		String pattern = "([a-z0-9_.-]+@[a-z0-9-]+\\.[a-z]{2,6})";
		if(eMail.matches(pattern)){
			System.out.println("Your E-Mail address is valid");
		}else{
			System.out.println("You entered a not valid E-Mail address");
		}

	}

}

Syndicate content

CafeWebmaster.com(CW) is a free online community for webdevelopers and beginners. Anybody can share their code, articles, tips, tutorials, code-examples or other webdesign related material on the site. Newbies can submit their questions and reply to existing questions. CW does not guarantee or warrant reliability of code, data and information published on the site. Use the site on your own risk. The site takes no responsibility of direct or indirect loss or any kind of harm to its users. The site also doesn't take responsibility of infected files or source code with any kind of infection or viruses, worms, spywares, malwares, trojan horses. CW reserves the right to edit, move, or delete any of content for any reason.