电话号码

简介: package testPhoneTel;import java.util.Scanner;import java.util.regex.Matcher;import java.util.regex.Pattern;public class test { public static void main(String[] args) { String str="13


package testPhoneTel;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class test {

	public static void main(String[] args) {
		String str="13112341234,010-12456789,01012456789,(010)12456789,00861012456789,+861012456789";

		Scanner input = new Scanner(System.in);
		boolean btn = true;
		String num;
		while (btn) {
			num = input.next();
			System.out.println(num + " is isMobile ? == " + isMobile(num)
					+ "\n");
			System.out.println(num + " is isPhone ? == " + isPhone(num) + "\n");
			if (num.equals("q")) {
				input.close();
				break;
			}

		}
		 Pattern p=Pattern.compile("1([\\d]{10})|((\\+[0-9]{2,4})?\\(?[0-9]+\\)?-?)?[0-9]{7,8}");        
	        Matcher m=p.matcher(str);        
	        while(m.find()){
	            System.out.println(m.group());         
	            System.out.println(m.group() + " is isMobile ? == " + isMobile(m+"")+ "\n");
				System.out.println(m.group() + " is isPhone ? == " + isPhone(m+"") + "\n");
	        }    

	}

	/**
	 * 手机号验证
	 * 
	 * @param str
	 * @return 验证通过返回true
	 */
	public static boolean isMobile(String str) {
		Pattern p = null;
		Matcher m = null;
		boolean b = false;
		p = Pattern.compile("^[1][3,4,5,8][0-9]{9}$"); // 验证手机号
		m = p.matcher(str);
		b = m.matches();
		return b;
	}

	/**
	 * 电话号码验证
	 * 
	 * @param str
	 * @return 验证通过返回true
	 */
	public static boolean isPhone(String str) {
		Pattern p1 = null, p2 = null;
		Matcher m = null;
		boolean b = false;
		p1 = Pattern.compile("^[0][1-9]{2,3}-[0-9]{5,10}$"); // 验证带区号的
		p2 = Pattern.compile("^[1-9]{1}[0-9]{5,8}$"); // 验证没有区号的
		if (str.length() > 9) {
			m = p1.matcher(str);
			b = m.matches();
		} else {
			m = p2.matcher(str);
			b = m.matches();
		}
		return b;
	}

	/**
	 * 验证邮箱地址是否正确
	 * 
	 * @param email
	 * @return
	 */
	public static boolean checkEmail(String email) {
		boolean flag = false;
		try {
			String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
			Pattern regex = Pattern.compile(check);
			Matcher matcher = regex.matcher(email);
			flag = matcher.matches();
		} catch (Exception e) {
			flag = false;
		}

		return flag;
	}



}






目录
相关文章
|
安全 前端开发 JavaScript
28、XSS常见payload
28、XSS常见payload
1014 0
|
Linux Shell 网络安全
Debian10.7 自动化安装镜像制作
Debian10.7 自动化安装镜像制作
1784 0
Debian10.7 自动化安装镜像制作
|
安全 NoSQL API
【漏洞复现】YApi NoSQL注入导致远程命令执行漏洞
YApi是一个API管理工具。在其1.12.0版本之前,存在一处NoSQL注入漏洞,通过该漏洞攻击者可以窃取项目Token,并利用这个Token执行任意Mock脚本,获取服务器权限。
3281 1
|
应用服务中间件 网络安全 nginx
|
Prometheus 监控 安全
SpringBoot Actuator未授权访问漏洞的解决方法
SpringBoot Actuator未授权访问漏洞的解决方法Actuator 是 SpringBoot 提供的用来对应用系统进行自省和监控的功能模块,借助于 Actuator 开发者可以很方便地对应用系统某些监控指标进行查看、统计等。
31258 0
|
SQL 监控 druid
Druid未授权访问 漏洞复现
Druid未授权访问 漏洞复现
18858 0
|
9月前
|
Ubuntu Linux
Linux系统管理:服务器时间与网络时间同步技巧。
以上就是在Linux服务器上设置时间同步的方式。然而,要正确运用这些知识,需要理解其背后的工作原理:服务器根据网络中的其他机器的时间进行校对,逐步地精确自己的系统时间,就像一只犹豫不决的啮齿动物,通过观察其他啮齿动物的行为,逐渐确定自己的行为逻辑,既简单,又有趣。最后希望这个过程既能给你带来乐趣,也能提高你作为系统管理员的专业素养。
1412 20
|
10月前
|
Linux
Debian下载ISO镜像的方法
步骤 1:访问Debian官方网站 打开你的网络浏览器,在地址栏中输入 https://www.debian.org/ 并回车,这将带你到Debian的官方网站。
1748 6
Debian下载ISO镜像的方法
|
Docker 容器
docker 换国内镜像源,docker换源
docker 换国内镜像源,docker换源
10852 91
|
Linux 数据安全/隐私保护 Python
使用Python实现Linux惠尔顿上网认证客户端
使用Python实现Linux惠尔顿上网认证客户端
748 0

热门文章

最新文章