手机号连号,顺序号验证

前端之家收集整理的这篇文章主要介绍了手机号连号,顺序号验证前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
package com.demo.test;

public class Test {

	public static void main(String[] args) {
		//手机连号设置
		int mobileCount = 6;
		String[]  mobile = {
				"13511111111","13555555555","13599999999","13512345678","13501234567","13576543210","13587654321","13501234012","13587654376"};
		for(int z = 0; z < mobile.length; z++) {
			//去除相同连号开始
			//相同连号0-9,10种匹配
			for(int i = 0; i <=9; i++) {
				String str = "";
				for(int j = 0; j < mobileCount; j++) {
					str += i;
				}
				mobile[z] = mobile[z].replace(str,"");
			}
			//去除相同连号结束
			//去除升序连号
			//10-连号设置+1为循环总个数
			for(int i = 0; i < 11-mobileCount; i++) {
				String str = "";
				for(int j = 0; j < mobileCount; j++) {
					str += i + j;
				}
				mobile[z] = mobile[z].replace(str,"");
			}
			//去除升序连号
			//去除降序连号
			//10-连号设置+1为循环总个数
			for(int i = 0; i < 11-mobileCount; i++) {
				String str = "";
				for(int j = 0; j < mobileCount; j++) {
					//9为降序起始数值
					str += 9-i-j;
				}
				mobile[z] = mobile[z].replace(str,"");
			}
			//去除降序连号
		}
		
		for(int z = 0; z < mobile.length; z++) {
			System.out.println(mobile[z]);
		}
	}

}

配合手机正则使用:var regName = /^1[3|4|5|8][0-9]\d{8}$/;

可直接用于后台验证手机号或前台js验证手机号

使用环境:

用户填写手机号,验证手机号是否为相同连号或升降序连号

如:

13511111111,13599999999,13501234567,13598765432

原文链接:https://www.f2er.com/regex/362005.html

猜你在找的正则表达式相关文章