@alviere/core 0.17.0 → 0.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs
CHANGED
|
@@ -398,6 +398,10 @@ class Validator {
|
|
|
398
398
|
if (trimmed.includes("..")) {
|
|
399
399
|
return "Please enter a valid email address.";
|
|
400
400
|
}
|
|
401
|
+
const localPart = trimmed.split("@")[0];
|
|
402
|
+
if (localPart.startsWith(".") || localPart.endsWith(".")) {
|
|
403
|
+
return "Please enter a valid email address.";
|
|
404
|
+
}
|
|
401
405
|
const emailRegEx = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/;
|
|
402
406
|
if (!emailRegEx.test(trimmed)) {
|
|
403
407
|
return "Please enter a valid email address.";
|
|
@@ -534,6 +538,7 @@ class Validator {
|
|
|
534
538
|
* for a legitimate name — callers are responsible for normalising the value
|
|
535
539
|
* to the API-accepted character set before sending (API regex:
|
|
536
540
|
* ^[a-zA-Z0-9' -]{1,40}$).
|
|
541
|
+
* Length is enforced to match API limits: min 1, max 40 characters.
|
|
537
542
|
* @param value - The value to validate
|
|
538
543
|
* @param fieldName - Optional field name for error message
|
|
539
544
|
*/
|
|
@@ -541,7 +546,11 @@ class Validator {
|
|
|
541
546
|
if (!value || typeof value !== "string") {
|
|
542
547
|
return fieldName ? `${fieldName} is required.` : "This field is required.";
|
|
543
548
|
}
|
|
544
|
-
|
|
549
|
+
const trimmed = value.trim();
|
|
550
|
+
if (trimmed.length > 40) {
|
|
551
|
+
return fieldName ? `${fieldName} must be no more than 40 characters long.` : "Must be no more than 40 characters long.";
|
|
552
|
+
}
|
|
553
|
+
if (!/^[-.,\p{L}\p{M}\s\d\u0027\u2019]+$/u.test(trimmed)) {
|
|
545
554
|
return fieldName ? `${fieldName} must contain only letters, numbers, spaces, hyphens, apostrophes, periods, and commas.` : "Must contain only letters, numbers, spaces, hyphens, apostrophes, periods, and commas.";
|
|
546
555
|
}
|
|
547
556
|
return null;
|