diff --git a/cp/bootstrap/helper.php b/cp/bootstrap/helper.php index 96afc8c..8f317d2 100644 --- a/cp/bootstrap/helper.php +++ b/cp/bootstrap/helper.php @@ -187,19 +187,14 @@ function validate_identifier($identifier) { $length = strlen($identifier); - if ($length < 3) { - return 'The contact ID seems too short. It should be at least 3 characters long. Please try again.'; + if ($length < 3 || $length > 16) { + return 'Identifier must be between 3 and 16 characters long. Please try again.'; } - if ($length > 16) { - return 'The contact ID seems too long. It should be no more than 16 characters. Please try again.'; - } + // Updated pattern: allows letters and digits at start and end, hyphens in the middle only + $pattern = '/^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/'; - $pattern1 = '/^[A-Z]+\-[0-9]+$/'; - $pattern2 = '/^[A-Za-z][A-Z0-9a-z]*$/'; - $pattern3 = '/^[a-zA-Z0-9]{16}$/'; - - if (!preg_match($pattern1, $identifier) && !preg_match($pattern2, $identifier) && !preg_match($pattern3, $identifier)) { + if (!preg_match($pattern, $identifier)) { return 'Your contact ID must contain letters (A-Z, a-z), digits (0-9), and optionally a hyphen (-). Please adjust and try again.'; } } diff --git a/epp/src/helpers.php b/epp/src/helpers.php index d2d010c..ca98144 100644 --- a/epp/src/helpers.php +++ b/epp/src/helpers.php @@ -169,19 +169,15 @@ function validate_identifier($identifier) { $length = strlen($identifier); - if ($length < 3) { - return 'Identifier type minLength value=3, maxLength value=16'; + if ($length < 3 || $length > 16) { + return 'Identifier must be between 3 and 16 characters long'; } - if ($length > 16) { - return 'Identifier type minLength value=3, maxLength value=16'; - } + // Updated pattern: allows letters and digits at start and end, hyphens in the middle only + $pattern = '/^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/'; - $pattern1 = '/^[A-Z]+\-[0-9]+$/'; - $pattern2 = '/^[A-Za-z][A-Z0-9a-z]*$/'; - - if (!preg_match($pattern1, $identifier) && !preg_match($pattern2, $identifier)) { - return 'The ID of the contact must contain letters (A-Z) (ASCII), hyphen (-), and digits (0-9).'; + if (!preg_match($pattern, $identifier)) { + return 'The ID must start and end with a letter or digit and can contain hyphens (-) in the middle.'; } }