📄 testphone.java
字号:
/*
* Created on Jul 7, 2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.arcmind.jsfquickstart.validation;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author Richard Hightower
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class TestPhone {
public static void main(String args[]){
String countryCode = "^[0-9]{1,2}";
String areaCode = "( |-|\\(){1}[0-9]{3}( |-|\\)){1}";
String prefix = "( |-)?[0-9]{3}";
String number = "( |-)[0-9]{4}$";
Pattern mask = Pattern.compile(countryCode+areaCode+prefix+number);
Matcher matcher = mask.matcher("1(520) 865-8653");
if (matcher.find()){
System.out.println("NUMBER MATCHES");
}else{
System.out.println("NO LOVE");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -