validate

Function validate 

Source
pub fn validate(
    code: &str,
    alphabet: &Alphabet,
    expected_length: usize,
    damm_table: &DammTable,
) -> ValidationResult
Expand description

Validate a promotional code and return detailed result.

This function checks:

  1. Code length matches expected length
  2. All characters are in the alphabet
  3. Damm check digit is correct

§Arguments

  • code - The code to validate (including check digit)
  • alphabet - The alphabet used for the code
  • expected_length - Expected total length (code_length + 1 for check digit)
  • damm_table - Damm table for check digit validation

§Returns

ValidationResult with detailed information about any validation failure.

§Example

use promocrypt_core::{validate, Alphabet, DammTable, ValidationResult};

let alphabet = Alphabet::default_alphabet();
let damm = DammTable::new(alphabet.len());

let result = validate("INVALIDCODE", &alphabet, 10, &damm);
// result will indicate specific failure reason