Home>Article>Java> Summary of regular verification frequently used in Java development

Summary of regular verification frequently used in Java development

Mary-Kate Olsen
Mary-Kate Olsen Original
2018-07-23 10:32:59 1454browse

This article mainly summarizes the commonly used regular verification in Java

1. Mobile phone number verification

public static boolean isMobile(String str) { Pattern p; Matcher m; boolean b; p = Pattern.compile("^[1][3,4,5,6,7,8,9][0-9]{9}$"); // 验证手机号 m = p.matcher(str); b = m.matches(); return b; }

2. Determine whether the obj object attributes are empty. If they are all empty, If it is not empty, it will return false

public static boolean checkFieldValueNull(Object obj){ Class clazz = obj.getClass(); for(; clazz != Object.class ; clazz = clazz.getSuperclass()) { Field[] fields=clazz.getDeclaredFields(); for(Field field:fields){ try { field.setAccessible(true); if("serialVersionUID".equals(field.getName())){ continue; } if (field.get(obj) != null) {//判断字段是否为空,并且对象属性中的基本都会转为对象类型来判断 return false; } } catch (IllegalAccessException e) { e.printStackTrace(); } } } return true; }

3. Determine whether the URL contains http://. If not, it will automatically add

url = url.substr(0,7).toLowerCase() == "http://" ? url : "http://" + url;
to the URL.

The above is the detailed content of Summary of regular verification frequently used in Java development. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn