Skip to content

Instantly share code, notes, and snippets.

@zeinabmohamed
Forked from sangramanand/ValidatePhoneNumber
Last active August 29, 2015 14:16
Show Gist options
  • Save zeinabmohamed/41af50b1bf34c7a11b4c to your computer and use it in GitHub Desktop.
Save zeinabmohamed/41af50b1bf34c7a11b4c to your computer and use it in GitHub Desktop.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* @author anand
*/
public class ValidatePhoneNumber {
public static void main(String[] argv) {
String phoneNumber = "1-(80..2)-321-0361";
System.out.println(phoneNumber.length());
String regex = "^\\+?[0-9. ()-]{10,25}$";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(phoneNumber);
if (matcher.matches()) {
System.out.println("Phone Number Valid");
} else {
System.out.println("Phone Number must be in the form XXX-XXXXXXX");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment