当前位置:网站首页>Common regular expressions - tool classes (mobile number, email, QQ, fax)
Common regular expressions - tool classes (mobile number, email, QQ, fax)
2022-06-26 10:45:00 【Slightly drunk CC】
Common regular expressions —— Tool class ( cell-phone number , mailbox ,QQ, Fax )
One 、 Front end verification
To be improved
Two 、 Background verification
package com.ccbx.ymjr.sms.utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** * Data validation using regular expressions */
public class RegexValidateUtil {
static boolean flag = false;
static String regex = "";
public static boolean check(String str, String regex) {
try {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
flag = matcher.matches();
} catch (Exception e) {
flag = false;
}
return flag;
}
/** * Verify email * * @param email * @return */
public static boolean checkEmail(String email) {
String regex = "^\\w+[-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$ ";
return check(email, regex);
}
/** * Verify phone number , All three carrier numbers can be verified ( No satellite communications 1349) * * China telecom signal segment 133,149,153,173,174,177,180,181,189,199 * China Unicom section 130,131,132,145,146,155,156,166,175,176,185,186 * China mobile segment 134(0-8),135,136,137,138,139,147,148,150,151,152,157,158,159,165,178,182,183,184,187,188,198 * The exclusive number segment of the network card ( It is used for surfing the Internet and sending and receiving SMS , Can't call ) * For example, China Unicom is 145 * Virtual operators * telecom :1700,1701,1702 * Move :1703,1705,1706 * Unicom :1704,1707,1708,1709,171 * Satellite communications : 1349 * Unknown segment :141、142、143、144、154 * * @param phone * @return */
public static boolean checkPhone(String phone) {
String regex = "^[1](([3|5|8][\\d])|([4][4,5,6,7,8,9])|([6][2,5,6,7])|([7][^9])|([9][1,8,9]))[\\d]{8}$";
return check(phone, regex);
}
/** * Verify the fixed line number * * @param telephone * @return */
public static boolean checkTelephone(String telephone) {
String regex = "^(0\\d{2}-\\d{8}(-\\d{1,4})?)|(0\\d{3}-\\d{7,8}(-\\d{1,4})?)$";
return check(telephone, regex);
}
/** * Verify fax number * * @param fax * @return */
public static boolean checkFax(String fax) {
String regex = "^(0\\d{2}-\\d{8}(-\\d{1,4})?)|(0\\d{3}-\\d{7,8}(-\\d{1,4})?)$";
return check(fax, regex);
}
/** * verification QQ number * * @param QQ * @return */
public static boolean checkQQ(String QQ) {
String regex = "^[1-9][0-9]{4,} $";
return check(QQ, regex);
}
}
remarks : This part of the mobile phone number regular expression reference : Civil pile
边栏推荐
- Adaptiveavgpool2d does not support onnx export. Customize a class to replace adaptiveavgpool2d
- echo $?
- Redis中执行Lua脚本
- Moore vote, leetcode169, leetcode229
- 【LeetCode】59. Spiral matrix II
- Yarn package management tool
- String constant pool, class constant pool, and runtime constant pool
- DBSCAN
- Hcia-dhcp experiment
- 2. merge two ordered arrays
猜你喜欢

Problems encountered in the application and development of Hongmeng and some roast

Flutter and native communication (Part 1)

Swiftui development experience: data layer of application design for offline priority

Postman入门教程

MySQL 11th job - view application

The sixth MySQL job - query data - multiple conditions

Jar version conflict resolution

DBSCAN

3行3列整形二维数组,求对角之和

Concise course of probability theory and statistics in engineering mathematics second edition review outline
随机推荐
Introduction to sysbench Basics
Opencv image processing - grayscale processing
Reshape a two-dimensional array with 3 rows and 3 columns to find the sum of the diagonals
Cmake / set command
MySQL Chapter 5 Summary
MySQL第八次作业
Omni channel, multi scenario and cross platform, how does app analyze channel traffic with data
Blog post index summary --c #
Use of exec series functions (EXECL, execlp, execle, execv, execvp)
Is it safe to use flush mobile phones to speculate in stocks? How to fry stocks with flush
Oracle11g reports an error when starting the database ora-27154: post/wait create failed
基础-MySQL
Progressive Web 应用程序PWA是应用程序开发的未来
MySQL第七次作业-更新数据
Installer MySQL sous Linux [détails]
MySQL 10th job - View
Global and Chinese market of recycled paper 2022-2028: Research Report on technology, participants, trends, market size and share
Adaptiveavgpool2d does not support onnx export. Customize a class to replace adaptiveavgpool2d
Flutter与原生通信(上)
What is LSP