From 9494b900337bc73e939f1ff47e9d843c3be394cd Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Fri, 26 Jun 2020 21:40:30 +0200 Subject: [PATCH] Add a facility for contact name validation --- src/main/java/envoy/util/Bounds.java | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/envoy/util/Bounds.java diff --git a/src/main/java/envoy/util/Bounds.java b/src/main/java/envoy/util/Bounds.java new file mode 100644 index 0000000..3306fa9 --- /dev/null +++ b/src/main/java/envoy/util/Bounds.java @@ -0,0 +1,32 @@ +package envoy.util; + +import java.util.regex.Pattern; + +/** + * Implements contact name validation. + *

+ * Project: envoy-common
+ * File: Bounds.java
+ * Created: 25.06.2020
+ * + * @author Kai S. K. Engelbart + * @since Envoy Common v0.1-beta + */ +public class Bounds { + + private Bounds() {} + + /** + * The regular expression against which contact names should be validated. + * + * @since Envoy Common v0.1-beta + */ + public static final Pattern CONTACT_NAME_PATTERN = Pattern.compile("^\\w[a-zA-Z0-9-]{2,15}$"); + + /** + * @param contactName the contact name to validate + * @return {@code true} if the given contact name is valid + * @since Envoy Common v0.1-beta + */ + public static boolean isValidContactName(String contactName) { return CONTACT_NAME_PATTERN.matcher(contactName).matches(); } +}