Import java. Io. ioexception;
Import java. util. RegEx. matcher;
Import java. util. RegEx. pattern;
Public class classpathresource {
Public static Boolean isphonenumbervalid (string phonenumber)
Boolean isvalid = false;
/*
* Acceptable telephone formats include:
*/
String expression = "^ \\(? (\ D {3 })\\)? [-]? (\ D {3 })[-
]? (\ D {5}) $ ";
/*
* Acceptable telephone formats include:
*/
String expression2 = "^ \\(? (\ D {3 })\\)? [-]? (\ D {4 })[-
]? (\ D {4}) $ ";
Charsequence inputstr = phonenumber;
Pattern pattern = pattern. Compile (expression );
Matcher = pattern. matcher (inputstr );
Pattern pattern2 = pattern. Compile (expression2 );
Matcher matcher2 = pattern2.matcher (inputstr );
If (matcher. Matches () | matcher2.matches ()){
Isvalid = true;
}
Return isvalid;
}
Public static void main (string [] ARGs) throws ioexception {
System. Out. println (classpathresource. isphonenumbervalid ("18352662160 "));
}
}
Reference: http://blog.csdn.net/boyupeng/article/details/6418074