Feature #10038
openFeature #10034: Evergreen Anniversary Sale Coupon Management in POS & Service Subscription
Coupon Code Input Validation Rules
0%
Description
- Coupon Code Input Validation Rules
- Field Name
Coupon Code
- Validation Rules
- 1. Required Field
The Coupon Code field is mandatory.
Validation Message:
`Coupon code is required.`
- 2. Minimum and Maximum Length
- Minimum length: 4 characters
- Maximum length: 20 characters
Validation Messages:
- `Coupon code must contain at least 4 characters.`
- `Coupon code cannot exceed 20 characters.`
- 3. Allowed Characters
The Coupon Code may contain only:
- Uppercase English letters: `A–Z`
- Numbers: `0–9`
- Hyphen: `-`
- Underscore: `_`
Valid Examples:
- `SAVE10`
- `WELCOME20`
- `SUMMER-2026`
- `SERVICE_PLAN10`
- `POS-NEW25`
Invalid Examples:
- `SAVE 10`
- `SAVE@10`
- `WELCOME#20`
- `COUPON%50`
- `SAVE.10`
Validation Message:
`Coupon code can contain only letters, numbers, hyphens, and underscores.`
- 4. Spaces Are Not Allowed
Spaces must not be allowed anywhere within the coupon code.
Examples:
- Invalid: `SAVE 10`
- Invalid: ` SUMMER10`
- Invalid: `SUMMER10 `
The system may automatically remove leading and trailing spaces, but spaces between characters must return an error.
Validation Message:
`Spaces are not allowed in the coupon code.`
- 5. Uppercase Conversion
The system should automatically convert entered letters to uppercase.
Examples:
- User enters: `save10`
- System stores: `SAVE10`
- User enters: `Summer-2026`
- System stores: `SUMMER-2026`
Coupon code validation during checkout must remain case-insensitive.
- 6. First Character Rule
The coupon code must begin with a letter or number.
It must not begin with:
- Hyphen
- Underscore
Valid:
- `SAVE-10`
- `10OFF`
- `POS_20`
Invalid:
- `-SAVE10`
- `_WELCOME20`
Validation Message:
`Coupon code must start with a letter or number.`
- 7. Last Character Rule
The coupon code must end with a letter or number.
It must not end with:
- Hyphen
- Underscore
Valid:
- `SAVE-10`
- `POS_20`
Invalid:
- `SAVE10-`
- `WELCOME_`
Validation Message:
`Coupon code must end with a letter or number.`
- 8. Consecutive Special Characters
The system should not allow consecutive hyphens or underscores.
Invalid Examples:
- `SAVE--10`
- `WELCOME__20`
- `POS-_10`
- `SERVICE_-20`
Validation Message:
`Coupon code cannot contain consecutive hyphens or underscores.`
- 9. At Least One Letter or Number
A coupon code cannot contain only hyphens or underscores.
Invalid Examples:
- `----`
- `____`
- `-_-_`
Validation Message:
`Coupon code must contain letters or numbers.`
- 10. Tenant-Level Uniqueness
The coupon code must be unique within the current company or tenant.
The uniqueness check must be case-insensitive.
Examples:
If `SAVE10` already exists, the following values must also be treated as duplicates:
- `save10`
- `Save10`
- `SAVE10`
Validation Message:
`This coupon code already exists.`
Different tenants may use the same coupon code.
- 11. Reserved Coupon Codes
The system should prevent reserved or system-related values from being used.
Recommended reserved codes:
- `ADMIN`
- `SYSTEM`
- `DEFAULT`
- `NULL`
- `UNDEFINED`
- `TEST`
- `DEMO`
Validation Message:
`This coupon code is reserved. Please enter another code.`
- 12. Duplicate Validation During Edit
When editing an existing coupon:
- The current coupon code must not be treated as a duplicate of itself.
- If the code is changed, the system must check uniqueness against all other non-deleted coupons.
- If the coupon has already been redeemed, the coupon code should become read-only.
- Recommended Regular Expression
```regex
^[A-Za-z0-9](?:[A-Za-z0-9]|[-_](?=[A-Za-z0-9])){2,18}[A-Za-z0-9]$
```
This validates:
- Length between 4 and 20 characters
- Starts with a letter or number
- Ends with a letter or number
- Allows letters, numbers, hyphens, and underscores
- Prevents consecutive special characters
- Prevents spaces and unsupported symbols
- Frontend Validation Example
```typescript
const COUPON_CODE_REGEX =
/^[A-Za-z0-9](?:[A-Za-z0-9]|[-_](?=[A-Za-z0-9])){2,18}[A-Za-z0-9]$/;
export const validateCouponCode = (value: string): string | null => {
const normalizedValue = value.trim().toUpperCase();
if (!normalizedValue) {
return "Coupon code is required.";
}
if (normalizedValue.length < 4) {
return "Coupon code must contain at least 4 characters.";
}
if (normalizedValue.length > 20) {
return "Coupon code cannot exceed 20 characters.";
}
if (!COUPON_CODE_REGEX.test(normalizedValue)) {
return "Use only letters, numbers, hyphens, and underscores. The code must start and end with a letter or number.";
}
return null;
};
```
- Recommended Form Behaviour
- Automatically convert input to uppercase.
- Automatically trim leading and trailing spaces.
- Do not allow unsupported special characters.
- Show remaining character count, such as `8/20`.
- Perform syntax validation immediately on blur.
- Perform uniqueness validation through the backend API.
- Disable the Save button until all validations pass.
- Store the normalised coupon code in uppercase.
Subtasks
Related issues
No data to display