Java tutorial
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static boolean checkEmail(String emailStr) { String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"; Pattern regex = Pattern.compile(check); Matcher matcher = regex.matcher(emailStr.trim()); return matcher.matches(); } public static String trim(String input) { if (input == null) return ""; StringBuilder sb = new StringBuilder(); for (int i = 0; i < input.length(); i++) { if (input.charAt(i) == ' ') { continue; } else { sb.append(input.charAt(i)); } } return sb.toString(); } }