The Validation tool class provides a way to verify the email format, whether it is IPv4, IPv6, whether Chinese, numeric, or regular expression validation.
The source code is as follows: (Click to download-Validateutils.java, Commons-lang-2.6.jar, Httpclient-4.3.3.jar)
ImportJava.util.regex.Matcher;ImportJava.util.regex.Pattern;Importorg.apache.commons.lang.StringUtils;Importorg.apache.http.conn.util.InetAddressUtils;/*** Validation Tool class **/ Public classValidateutils {Private Static transient FinalString Regex_is_chinese = "^[\\u4e00-\\u9fa5][\\u4e00-\\u9fa5]*[\\u4e00-\\u9fa5]$"; Private Static transient FinalString Regex_is_email = "^ ([a-z0-9a-z]+[-_|\\.]?) +[a-z0-9a-z]@ ([a-z0-9a-z]+ (-[a-z0-9a-z]+) \ \.) +[a-za-z]{2,}$ "; /*** Email * *@paramEmail * a {@linkjava.lang.String} object. * @returnValidation Results*/ Public Static Booleanisemail (String email) {returnisMatch (email, regex_is_email); } /*** Email * *@paramEmail * a {@linkjava.lang.String} object. * @returnValidation Results*/ Public Static Booleanisnotemail (String email) {return!isemail (email); } /*** is IPv4 * *@paramIPv4 * A {@linkjava.lang.String} object. * @returnValidation Results*/ Public Static BooleanisIPv4 (String IPv4) {returninetaddressutils.isipv4address (IPv4); } /*** is IPv4 * *@paramIPv4 * A {@linkjava.lang.String} object. * @returnValidation Results*/ Public Static BooleanisNotIPv4 (String IPv4) {return!isIPv4 (IPv4); } /*** is IPv6 * *@paramIPv6 * A {@linkjava.lang.String} object. * @returnValidation Results*/ Public Static BooleanisIPv6 (String IPv6) {returninetaddressutils.isipv6address (IPv6); } /*** is IPv6 * *@paramIPv6 * A {@linkjava.lang.String} object. * @returnValidation Results*/ Public Static BooleanisNotIPv6 (String IPv6) {return!isIPv6 (IPv6); } /*** is Chinese * *@paramStr * a {@linkjava.lang.String} object. * @returnValidation Results*/ Public Static BooleanIschinese (String str) {returnIsMatch (str, regex_is_chinese); } /*** is the number * *@paramStr * a {@linkjava.lang.String} object. * @returnValidation Results*/ Public Static Booleanisnumeric (String str) {returnstringutils.isnumeric (str); } /*** is the number * *@paramStr * a {@linkjava.lang.String} object. * @returnValidation Results*/ Public Static Booleanisnotnumeric (String str) {return!isnumeric (str); } /*** Regular Expression validation * *@paramStr * a {@linkjava.lang.String} object. * @paramRegex * A {@linkjava.lang.String} object. * @returnValidation Results*/ Public Static BooleanIsMatch (String str, string regex) {FinalPattern pattern =pattern.compile (regex); FinalMatcher Matcher =Pattern.matcher (str); if(!Matcher.find ()) { return false; } return true; }}
Validation Tool Class-Validateutils.java