Validation Tool Class-Validateutils.java

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.