Validating email addresses and UK postcodes with AskiaScript

Note: This topic provides descriptions and examples of how to validate email and postcode data captured during fieldwork. It assumes you already know how to define AskiaScript conditions. For an introduction to creating custom routing conditions, see custom routing conditions in AskiaScript. A full description of the AskiaScript language can be found here.

The AskiaDesign training course provides a broad introduction to routing instructions in AskiaDesign (contact Askia if you would like to arrange training sessions). However, the Askia system provides several more powerful routing capabilities that go beyond the scope of the course. This topic explains how to use the functions isEmail and isUKPostcode to validate email and postcode responses.

The following script conditions allow you to check the format of email addresses or UK postcodes collected during fieldwork. They do not check the existence of the email addresses or postcodes given by respondents, only that they are in the expected format.

IsEmail

This function verifies that the response to a question conforms to a valid email address format (x@x.xxx). It also checks for invalid characters and returns 0 if any of them are present. For example:

IsEmail(??Q1??) 'askiascript 1.0

Q1.Value.IsEmail() 'askiascript 2.0
returns 1 if the response to Q1 gives an email address in a valid format (of course, it still might not be the correct email address for the respondent, but the function allows you to improve the quality of data collected).

IsUKPostcode

This function verifies that the response to a question is a properly formed UK postcode, and returns 1 (true) if it is valid or 0 (false) if it is invalid. For example:

'askiascript 1.0
IsUKPostCode("L1 2AX")
IsUKPostCode("EC2A 3QT")
IsUKPostCode("10031")
IsUKPostCode("GU1234")

'askiascript 2.0
("L1 2AX").IsUKPostCode()

The first two examples will both return 1 as they are in the correct format for a UK postcode; the third and fourth will return zero, as they are not. The function only checks that the letters, numbers and intervening space follow the rules of UK postcodes – it does not validate that the postcode exists against a database of postcodes.

Create your own Knowledge Base