Pattern: Character masks

“Character masks” is one of the patterns that you can select on the Match panel. With this pattern you can easily make a field match a certain combination of letters, digits, and punctuation. This pattern uses text masks similar to the masks used by masked edit controls in various development tools to force the user to enter a certain combination of letters, digits, and/or punctuation.

This example shows how you can use the “character masks” pattern to easily match an SKU code that consists of 6 letters identifying the supplier, a hyphen, and 3 digits indicating the product number. You can find this example as “Pattern: character masks” in the RegexMagic library.

  1. Click the New Formula button on the top toolbar to clear out all settings on the Samples, Match, and Action panels.
  2. On the Samples panel, paste in one new sample:
    JGSOFT-001
  3. On the Match panel, set “begin regex match at” to “start of text”, and set “end regex match at” to “end of text”.
  4. Click the Add First Field button to add field 1.
  5. In the “pattern to match field” drop-down list, select “character masks”.



  6. Enter this character mask:
    LLLLLL-999
  7. Set the “field validation mode” to “average”.
  8. On the Regex panel, select “C# (.NET 2.0–7.0)” as your application, turn off free-spacing, and turn off mode modifiers. Click the Generate button, and you’ll get this regular expression:
    \A[a-z]{6}-[0-9]{3}\z

    Required options: Case insensitive.
    Unused options: Exact spacing; Dot doesn’t match line breaks; ^$ don’t match at line breaks; Numbered capture.

  9. The Samples panel now shows the regular expression correctly matches the SKU code.:
    JGSOFT-001

Related Examples

Reference