This section contains a step-by-step guide to creating an application that captures a single field which conforms to a certain regular expression. This could be a date, some code, etc. The more specific the data is, the easier it would be to capture it. In this guide we will capture an alphanumeric code, for example: X6Yz647a.
Note: The regular expression syntax is derived from ICU regular expressions, with some minor features not supported. See the Regular Expressions section in the ICU User Guide.
Also you can implement any string predicate and use it for additional validation after the data has passed the regular expression check — for example, calculate the field's checksum. To do so, implement Predicate<T> for the String type and set it as the additional validation callback using setOnValidate. An alphanumeric code needs no additional checks, so this step is skipped here.
IDataCaptureService dataCaptureService = engine.createDataCaptureService( "", callback );
IDataCaptureProfileBuilder profileBuilder = dataCaptureService.configureDataCaptureProfile()
.setRecognitionLanguage( "English" );
profileBuilder.addScheme( "sampleScheme" )
.setName( "Sample Profile" )
.addField( "sampleField" )
.setName( "Some Alphanumeric Code" )
.setRegEx( "([a-zA-Z]+[0-9]+|[0-9]+[a-zA-Z]+)[0-9a-zA-Z]*" );
See the description of classes and methods for Android OCR development in the API Reference section.