Demo entry 6899860

jd

   

Submitted by jd on Oct 09, 2019 at 08:07
Language: Java. Code size: 798 Bytes.

public class Main {
	
	public static void main(String[] args) {
		if (Main.isNumberLegal("3342392")) {
			System.out.println("合法");
		}
	}
	
	public static boolean isNumberLegal(String phoneNumber) {
		if (phoneNumber.length() != 10 && phoneNumber.length() != 7) {
			new Exception("非法:号码格式错误").printStackTrace();
			return false;
		}
		
		if (!StringUtil.isNumer(phoneNumber)) {
			new Exception("非法:号码必须为数字").printStackTrace();
			return false;
		}
		
		phoneNumber = StringUtil.substring(phoneNumber, phoneNumber.length() - 7, phoneNumber.length());
		
		char[] prefixCode = phoneNumber.toCharArray();
		if (prefixCode[0] == '0' || prefixCode[0] == '1') {
			new Exception("非法:前缀码必须为非‘0’ ‘1’ 开头的数字").printStackTrace();
			return false;
		}
		
		return true;
	}

}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).