Survey123 input mask

1348
7
05-08-2018 08:54 AM
Highlighted
New Contributor II

I'm trying to create a regex or something else that will allow the user to enter: Aa0 Aa0 and do this unlimited times or until field length hits it's max or just once

A - capital letter
a - small letter
0 - number

Reply
0 Kudos
7 Replies
Highlighted
Esri Esteemed Contributor

A regex can be written to validate the text, but an input mask cannot be made for an arbitrary length string.  the regex expression would be:

([A-Z][a-z][0-9] )+

assuming that at least one grouping of characters is required; change the + to * to allow empty results.

Reply
0 Kudos
Highlighted
New Contributor II

Is there another field in survey123 that I can use to output what I described?

Using the expression above or other ones that I have does not work and shows the ( ) +/* in the output text

Reply
0 Kudos
Highlighted
Esri Esteemed Contributor

Hi Matt,

the regex was intended to be used in the constraint column as part of a regex() function validating the pattern.  See the 'Regular Expressions' subsection in Formulas—Survey123 for ArcGIS | ArcGIS for more information.

Highlighted
New Contributor II
regex(., '{A-Z][a-z][0-9]+' )

I'm trying to use this, but I don't know what it will allow me to input to make it valid...Or4 doesn't work.

I'm having a little trouble understanding how to formulate it

Never mind I fixed my own problem.

Thank you for your help

Reply
0 Kudos
Highlighted
Esri Esteemed Contributor

Hi Matt,

For more information on regular expressions, I might suggest Regular Expressions - JavaScript | MDN  as a reference document; I also use https://regex101.com  to test the expressions.  

The evaluator '{A-Z][a-z][0-9]+' has an issue - the first brace is a curly brace instead of a square brace.  Square braces are used to group sets of characters together - [A-Z] looks for an uppercase letter, [a-z] looks for a lower case letter, [0-9] looks for a numeric digit.  The pattern you gave (Aa0 ) indicates that these should be grouped together using (); I also included a space as that was what you typed initially (you could also use \s instead of the space, though that would match other whitespace characters):

([A-Z][a-z][0-9] )

You wanted to match at least 1 and possibly more repetitions of this, the + (or * for 0 or more) is used to repeat a pattern:

([A-Z][a-z][0-9] )+

To ensure that the answer has nothing but this pattern, we should also specify to start the match at the beginning (^) and only finish at the end ($)

^([A-Z][a-z][0-9] )+$

Reply
0 Kudos
Highlighted
New Contributor II

All this makes perfect sense and I do understand more now, but have issue with this:

regex(., ^([A-Z][a-z][0-9] )+$)
Reply
0 Kudos
Highlighted
Esri Esteemed Contributor

The regular expression evaluator should be in quotes:

regex(., "^([A-Z][a-z][0-9] )+$")

Reply
0 Kudos