StringUtil对字符串类型参数进行校验的工具类
来源:互联网 发布:摩天轮票务 知乎 编辑:程序博客网 时间:2024/06/05 06:21
1.对字符串类型参数进行校验的工具类
import java.text.DecimalFormat;import java.util.regex.Matcher;import java.util.regex.Pattern;public class StringUtil { public static boolean isNull(Object... obj){ return !isNotNull(obj); } public static boolean isNotNull(Object... obj){ if(obj != null){ for (Object o : obj) { if(o == null){ return false; } } }else{ return false; } return true; } public static boolean isEmpty(String key) { return !isNotEmpty(key); } public static boolean isNotEmpty(String key) { if (key!=null && !"".equals(key.trim())){ return true; } return false; } public static boolean isNotEmpty(String... keys) { return !isEmpty(keys); } public static boolean isEmpty(String... keys) { for (String key : keys) { if (StringUtil.isEmpty(key)) { return true; } } return false; } public static String decimalFormatPrice(String param) { if (param == null || "".equals(param)) { param = "0.00"; } double tmp = Double.parseDouble(param); DecimalFormat df = new DecimalFormat("0.00"); return df.format(tmp); } public static String cleanXss(String str) { if (str == null || "".equals(str.trim())) { return ""; } str = str.replaceAll(" ", ""); return str; } /** * @param str * @param trim * @return * @description 以*(分号)分隔的字符串,去除首尾的*(分号)。 * @author qinhc * @createTime 2015上午11:05:00 */ public static String StrRemoveTrim(String str, String trim) { // str=;2;; String resultStr = ""; String[] strList = str.split(trim); for (String s : strList) { if (!"".equals(s) && null != s) { resultStr = resultStr + s + trim; } } if (resultStr.length() > 0) { resultStr = resultStr.substring(0, resultStr.length() - 1); } return resultStr; } /** * 是否手机号 简单校验11位数字 * * @param str * @return * @author wangrq1 */ public static boolean isPhone(String str) { Matcher m = NUM_11.matcher(str); return m.matches(); } static Pattern NUM_11 = Pattern.compile("\\d{11}"); /** * 生产指定长度的由大写字母和数字组成的字符串 add by yezhenyue on 2016-03-29 * @param len * @return */ public static String randomStr(int len) { if (len == 0) { return ""; } int a = (int) (Math.random() * 2); if (a == 0) { return ((int) (Math.random() * 10)) + randomStr(len - 1); } else { return ((char) ((int) (Math.random() * 26) + 65)) + randomStr(len - 1); } } public static void main(String[] args) { System.out.println(isPhone("18001141691")); System.out.println(isPhone("")); }}
阅读全文
0 0
- StringUtil对字符串类型参数进行校验的工具类
- StringUtil 字符串工具类
- StringUtil(字符串工具类)
- 字符串工具类 StringUtil.java
- 定义字符串工具类StringUtil
- java 开发中常用的字符串工具类,StringUtil
- 阿帕奇,StringUtil工具类,各种常用字符串的处理
- 用正则表达式对qlineedit的输入参数进行校验
- StringUtil工具类的常用方法
- StringUtil字符串工具-功能扩展
- StringUtil 字符串处理的公共类
- C#(asp.net)对字符串的操作公共类(StringUtil.cs)
- Flex StringUtil工具类
- java StringUtil 工具类
- 工具类StringUtil.java
- StringUtil工具类
- 工具类StringUtil
- StringUtil工具类
- svn配置脚本 防止删除文件和空注释
- Unity3d 插值同步
- 用原生JS实现轮播图
- 灵活无成本的ITSM系统|ServiceHot ITSOM
- Understanding LSTM Networks
- StringUtil对字符串类型参数进行校验的工具类
- 拷贝构造
- 灯泡开关问题----bulb switcher,from leetcode
- js中的事件委托或是事件代理详解
- void Update ( ) 更新 void FixedUpdate ( )
- 谈谈对Spring IOC的理解
- 使用py-faster-rcnn来训练voc2007数据集(Ubuntu)
- Kotlin语言学习之定义变量(var,val)、方法(fun)
- php.ini