You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
955 B

package hs.fulda.de.ci.exam.project;
import java.util.regex.Pattern;
public class SmsNotification extends Notification {
String to;
String content;
public SmsNotification(String to, String content) {
super();
this.to = to;
this.content = content;
}
@Override
public boolean sendNotification() {
if (isValidEmail(to)) {
System.out.println("SMS is sent to " + to);
return true;
}
System.out.println("Invalid Number");
return false;
}
private boolean isValidEmail(String to) {
String regexPattern = "(\\(?([\\d \\-\\)\\–\\+\\/\\(]+){6,}\\)?([ .\\-–\\/]?)([\\d]+))";
return patternMatches(to, regexPattern);
}
public static boolean patternMatches(String emailAddress, String regexPattern) {
return Pattern.compile(regexPattern)
.matcher(emailAddress)
.matches();
}
}