Common Java tools-field verification tool validatorutil

Source: Internet
Author: User

A tool used to judge fields. It is essential for each project. After a brief summary, there are optimization tools or more suggestions, which can be continuously improved.

Import Java. util. regEx. matcher; import Java. util. regEx. pattern; /*** field verification tool * @ author lixinglei **/public class validatorutil {/*** determines whether it is a floating point number or an integer * @ Param Str * @ return true or false */ public static Boolean isnumeric (string Str) {pattern = pattern. compile ("^ (-? \ D +) (\. \ D + )? $ "); Matcher isnum = pattern. matcher (STR); If (! Isnum. matches () {return false;} return true ;} /*** determine whether the email format is correct * @ Param Str * @ return Boolean */public static Boolean isemail (string Str) {If (isempty (STR) return false; return Str. matches ("^ [\ W-] + (\\. [\ W-] +) * @ [\ W-] + (\\. [\ W-] +) + $ ");} /*** determine whether the string is a valid mobile phone number. The string starts with "11 bits 13 14 15 18" * @ Param Str * @ return Boolean */public static Boolean ismobile (string Str) {If (isempty (STR) return false; return Str. matches ("^ (13 | 14 | 15 | 18) \ D {9} $ ");} /*** determine whether it is a number * @ Param Str * @ return */public static Boolean isnumber (string Str) {try {integer. parseint (STR); Return true;} catch (exception ex) {return false;}/*** determines whether the string is non-empty (including null and "") * @ Param Str * @ return */public static Boolean isnotempty (string Str) {If (STR = NULL | "". equals (STR) return false; return true;}/*** determines whether the string is non-empty (including null and "","") * @ Param Str * @ return */public static Boolean isnotemptyignoreblank (string Str) {If (STR = NULL | "". equals (STR) | "". equals (Str. trim () return false; return true;}/*** determines whether the string is null (including null and "") * @ Param Str * @ return */public static Boolean isempty (string Str) {If (STR = NULL | "". equals (STR) return true; return false;}/*** determines whether the string is null (including null and "","") * @ Param Str * @ return */public static Boolean isemptyignoreblank (string Str) {If (STR = NULL | "". equals (STR) | "". equals (Str. trim () return true; return false;} // disable the instantiation of private validatorutil (){}}

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.