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 (){}}