Validate whether a coupon code is well-formed according to a set of format and character rules.
Coupon Code Checker
gfgYou are given a coupon code as a string. Determine whether it is valid according to the following rules:
-.Return whether the code is valid.
Because the exact business rules can vary by company, treat this as a structured validation problem: inspect the string carefully, enforce the required format, and reject anything that breaks the rules.
code representing the coupon code.true if the code satisfies all rules.false.1 <= code.length <= $10^{5}$Example 1
Input
code = "ABCD-1234-EFGH"
Output
true
Explanation
The code uses only allowed characters and matches the expected block-separated format.
Example 2
Input
code = "ABCD_1234"
Output
false
Explanation
The underscore is not an allowed character, so the code is invalid.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.