Here you can find the source of isEmail(final String email)
Parameter | Description |
---|---|
a parameter |
public static boolean isEmail(final String email)
//package com.java2s; /*/* w w w. ja v a 2s . c om*/ * Copyright [2011] [C.H Li http://code.google.com/p/idocbox-common/] * Licensed to the Chunhui Li(C.H Li) under one or more contributor license agreements. * See the NOTICE file distributed with this work for additional information * regarding copyright ownership. * * C.H Li licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { /** * Is given email format correct? * * @param email * @return true:ok, false: error. */ public static boolean isEmail(final String email) { boolean isMatched = false; String check = "^([a-z0-9A-Z]+[-|//.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?//.)+[a-zA-Z]{2,}$"; isMatched = isMatched(email, check); return isMatched; } /** * Is given string's format correct? * * @param str * string. * @param regExp * regular expression. * @return true:ok, false: error. */ public static boolean isMatched(final String str, final String regExp) { boolean isMatched = false; Pattern regex = Pattern.compile(regExp); Matcher matcher = regex.matcher(str); isMatched = matcher.matches(); return isMatched; } }