Project

General

Profile

Edit Copy Actions

Feature #10038

open

Feature #10034: Evergreen Anniversary Sale Coupon Management in POS & Service Subscription

Coupon Code Input Validation Rules

Added by Yalavarthi Thriveni 5 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
07/30/2026
Due date:
% Done:

0%

Estimated time:

Description

  1. Coupon Code Input Validation Rules
  1. Field Name

Coupon Code

  1. Validation Rules
  1. 1. Required Field

The Coupon Code field is mandatory.

Validation Message:
`Coupon code is required.`

  1. 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.`
  1. 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.`

  1. 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.`

  1. 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.

  1. 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.`

  1. 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.`

  1. 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.`

  1. 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.`

  1. 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.

  1. 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.`

  1. 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.

  1. 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
  1. 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;
};
```
  1. 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.

Add

Subtasks


Add

Related issues

No data to display

Edit Copy Actions

Also available in: Atom PDF