Using scanning validation patterns Patterns are a description of what characters you expect to be in an open response variable. You have to define them for each variable that uses them. There are two types of scanning validation in Snap, ‘Spelling‘ and ‘Patterns‘. Spelling validation checks a response against a stored dictionary of words, and tries to match responses to words in the dictionary. Pattern validation depends on you creating the pattern of characters that you expect a response to be. It is most useful for responses such as dates, telephone number and zip codes. There are different versions of spelling and pattern validation for handwritten and printed characters. You can create one or more scanning validation patterns for each variable in your survey. Each pattern matches an expected response. You create a pattern by telling Snap how many of which characters you are expecting. For example, you could create several scanning patterns for a phone number. A pattern that just expects the digits 0 – 9 A pattern that expects a + as the first character A pattern that allows you to have the characters +, ( and ) as well as digits The software would then check through each pattern in turn to see if it could match the scanned characters to the ones in the pattern, for example, it would assume that “l” was a one, rather than a lower case L. See more >Hide this content > This worksheet provides: Some standard scanning validation patterns with instructions on adding them to your variables (See Option A) Instructions on creating your own validation pattern for a simple user ID (See Option B) Set a variable to use a pattern Open the survey in Questionnaire mode. Select the question that you wish to apply the pattern to (e.g. one asking “What is the phone number?”) Press [Alt]+[Enter] to display the Variable Properties dialog. Scroll to display the Scanning Validation property and change it from None to Pattern. This is the pattern for hand-written response. Click OK to close the Variable Properties and then open the Variables window. Locate the variable in the list which you set to Pattern and double click to open the Variable Details window. Click on the Toggle Definitions icon and you will see Pattern selected in the Scanning Validation dropdown list. Click on the button with 3 dots to open the Pattern Match List dialog which lists all existing patterns for this question (currently none). Tell me how to do this >Hide this content > Option A: Apply a sample pattern You can create patterns by pasting pattern definitions in the design field. This step supplies some example patterns for dates, zip/post codes and phone numbers and shows you how to paste them in. Set a variable to use a pattern Click [New…] on the Pattern Match List dialog to create a pattern. The Pattern Match Details dialog opens. Use [Ctrl]+[C] to copy the sample pattern text that you require from the ‘Sample Scanning validation patterns’ table below step 10. Please note that there should be no line breaks. Use [Ctrl]+[V] to paste the pattern text into the Pattern field. Copy the text in the pattern to replace column if you wish to convert the response into a standard format. Paste this into the Replace With field. Click [OK] to save the pattern. Create any other patterns that you wish to use with on this variable (for example, add another phone number format). You can test multiple patterns by clicking [Test All] on the patterns list and then entering sample responses. Once you have tested your patterns are working correctly, click [OK] to return to the Variable Details window. Click to save the changes. Sample scanning validation patterns Definition Pattern to copy Pattern to replace (optional) Effect of replacement US ZIP code patterns 5-digit ZIP code \d{5} 5+4 digit ZIP code (separator is any non-numeric) (\d{5})\D(\d{4}) \1-\2 Enforces “-” between parts of ZIP code 2 character state code with optional space and 5-digit ZIP code ([A~Za~z]{2})\s?(\d{5}) \1 \2 Enforces space between characters and digits 2 character state code with optional space and 5+4 digit ZIP code ([A~Za~z]{2})\s?(\d{5})\D(\d{4}) \1 \2-\3 Enforces space between characters and digits and “-” between parts of ZIP code UK Postcode patterns Area and district (one or two letters followed by one or two digits) optional space, sector and unit ([A~Za~z]{1,2})(\d{1,2})\s?(\d)([A~Za~z]{2}) \1\2 \3\4 Enforces space between district and sector Area and district (one or two letters followed by one digit and one letter) optional space, sector and unit ([A~Za~z]{2})(\d[A~Za~z]{1})\s?(\d)([A~Za~z]{2}) \1\2 \3\4 Enforces space between district and sector Date patterns 4 – 6 digit date (1 or 2 day and month digits and 2 year digits). Valid for US or UK dates (\d{1,2})\D(\d{1,2})\D(\d{2}) \1-\2-\3 Places “-” as a separator between elements of date. For a different separator, replace “-” with your chosen character. 6 -8 digit date (1 or 2 day and month digits and 4 year digits). Valid for US or UK dates (\d{1,2})\D(\d{1,2})\D(\d{4}) \1-\2-\3 Places “-” as a separator between elements of date. For a different separator, replace “-” with your chosen character. UK Phone number patterns 0 plus 9 or 10 digits with spaces permitted anywhere (e.g. 01424 280 800) 0\s?(\d)\s?(\d)\s?(\d)\s?(\d)\s?(\d)\s?(\d)\s?(\d)\s?(\d)\s?(\d)\s?(\d)\s?(\d?) 0\1\2\3\4\5\6\7\8\9\10 Remove all optional spaces (would give 01424280800) UK number with brackets (e.g. (01424) 280 800) \((\d{3,6})\)\s?(\d{3})\s?(\d{2,4}) \1\2\3 Remove brackets and optional spaces (would give 01424280800) International number e.g. +44 1424 28000) \+44\s?(\d{2,6})\)?\s?(\d{3})\s?(\d{2,4}) 0\1\2\3 Remove international code and optional spaces (would give 01424280800) International number with “(0)” (e.g. +44 (0) 1424 28000) \+44\s?\(0\)\s?(\d{2,6})\)?\s?(\d{3})\s?(\d{2,4}) 0\1\2\3 Remove international code and optional spaces (would give 01424280800) US phone number patterns 7 digit number with optional spaces or dashes (e.g. 610-8700) (\d{3})[ -\~]?\d{4}) \1-\2 Replace optional spaces with dashes 10 digit phone number with optional brackets spaces or dashes (e.g. (603) 610 8700) \(?(\d{3})\)?[ -\~]?(\d{3})[ -\~]?(\d{4}) \1-\2-\3 Remove brackets and replace optional spaces (would give 603-610-8700) International number (e.g. +1-603-610 -8700) \+1[ -\~]?\(?(\d{3})\)?[ -\~]?(\d{3})[ -\~]?(\d{4}) \1-\2-\3 Remove international code and brackets and replace optional spaces (would give 603-610-8700) Value for currency Number of any length with no decimal places (e.g. 123) (\d+) \1.00 Add empty decimal places (123.00) Number of any length with decimal point and two decimal places (e.g. 123,45) (\d+)[ ‘\*\,~\._~`\~](\d{2}) \1.\2 Remove any non-standard decimal point character and replace with “.” (123.45) One or two digits with pence marker (e.g. 34p) (\d{1,2})[Pp] 00.\1 Convert value into decimal place (0.34) Tell me how to do this >Hide this content > Option B: Set up your own validation pattern This section shows how to create a simple validation pattern. The example is a pattern for an ID of two digits followed by five letters (digits can be separated from the letters by a space). The pattern removes spaces from the ID before entering the response in Snap. Set a variable to use a pattern. Click [New…] on the Pattern Match List dialog to create a pattern. The Pattern Match Details dialog opens. Click the button with 3 dots to the right of the Pattern field to open the Pattern Item dialog. Define the first element to match in your pattern. This will be two digits.Select Digit (0 to 9). Set the repetitions to be Exactly 2 in the Repetition area. Select Remember. This means that you will be able to replace parts of the pattern. Click [OK] to return to the Pattern Match Details dialog. The pattern item is described in the Description. It’s remembered as item \1 and looks for 2 digits. Now to insert a pattern item for a possible space. Put the cursor in the Pattern field at the end of the text and click the button with 3 dots again. Select Space. Set the repetitions to be 0 or more in the Repetition area. Click [OK] to save that part of your pattern. Now to define the letters in the pattern. Put the cursor in the Pattern field at the end of the text and click the button with dots again. Click “A”, hold down [Shift] and then click “Z” in the list of possible characters. Set the repetitions to be Exactly 5 in the Repetition area. Select Remember. Click [OK] to save this part of your pattern. This part of the pattern is remembered as item \2 and looks for 5 characters. Enter \1\2 in the Replace With field of the Pattern Match Details dialog. The \1 refers to your first remembered pattern item and the \2 refers to the second remembered pattern. Any spaces are discarded. Enter a sample user ID in the Test field. Any spaces that separate the numbers from the letters will be removed in the Replace field. This shows what would happen to scanned text in the survey. The Replace text will be stored in Snap. Click [OK] to save your pattern. If you want to use this pattern on other variables, you can copy the pattern definition text and paste it into a new pattern as described in Option A: Apply a sample pattern. Tell me how to do this >Hide this content > Further reading The Getting Started with Scanning guide describes how to set up spelling validation (for handwritten answers). It also has an example: Setting up quantity questions for scanning. The help includes a topic on setting up a scanning validation pattern for a name. The terms you can enter directly in the pattern definition field are defined in the topic: Pattern matching expressions. If there is a topic you would like a worksheet on, email to snapideas@snapsurveys.com