http://www.eobjects.dk/datacleaner/IconUserGuide.png

Validation Rule: Regex validation

back to DataCleaner | back to DataCleanerUserGuide

The Regex validation rule matches values against a regular expression. Writing regular expressions can be very effective and provide brilliant validation semantics.

Email address example

Consider this (simplified, but illustrative) regular expression for validating email addresses:

 [a-z0-9]*@[a-z0-9]*.[a-z]{2,4}
  • The brackets define a range of characters, ie. the [a-z0-9] token is translated to "all lowercase letters or all numbers".
  • The trailing wildcard * indicates that characters in the range can occur any number of times.
  • The literal @ is simply a litteral, representing the nescesary "at" literal in an email address.
  • Once again the range described above occurs in the pattern.
  • A dot and a 2-4 letter suffix is required for an emailaddress to be valid: .[a-z]{2,4}.

Note: The example is not fully valid, since uppercase and some special characters can in fact occur in valid email addresses. If you need to validate email addresses, instead use this pattern:

 [a-zA-Z0-9._%+-]*@[a-zA-Z0-9._%+-]*.[a-z]{2,4}

Regex samples

DataCleaner-GUI comes pre-packaged with a lot of regex samples. Look for them in the samples/regexes folder. You can import them by going to the File menu and selecting Load regexes from properties file.