I've placed a regex based constraint on a string fied to get a serial
number. It's supposed to be a 10 digit string. Here's the format I'm
using:
constraint="regex(., '^\d\d\d\d\d\d\d\d\d\d$')"
It ensures that the string is at least 10 digits long. However, it
also accepts strings longer than 10 digits. I've tried looking into
the ODK Collect code but this seems to be part of the javarosa
specifications that aren't included in the source. Please help.
^[0-9]{10,}$ will match only numbers greater than 10 digits in length.
Also, in the input control XML, use appearance="numbers" to allow for a
string field with a numbers keyboard. Try both.
···
On Sat, Feb 4, 2012 at 12:04, Asim Fayaz wrote:
> I've placed a regex based constraint on a string fied to get a serial
> number. It's supposed to be a 10 digit string. Here's the format I'm
> using:
>
> constraint="regex(., '^\d\d\d\d\d\d\d\d\d\d$')"
>
> It ensures that the string is at least 10 digits long. However, it
> also accepts strings longer than 10 digits. I've tried looking into
> the ODK Collect code but this seems to be part of the javarosa
> specifications that aren't included in the source. Please help.
>
> Asim
>
> --
> Post: opendatakit@googlegroups.com
> Unsubscribe: opendatakit+unsubscribe@googlegroups.com
> Options: http://groups.google.com/group/opendatakit?hl=en
I only want strings that have 10 digits. No more, no less. I tried the
string you suggested and it also allows 11 or more digits.
Asim
···
On Feb 5, 1:20 am, Yaw Anokwa wrote:
> Asim,
>
> ^[0-9]{10,}$ will match only numbers greater than 10 digits in length.
> Also, in the input control XML, use appearance="numbers" to allow for a
> string field with a numbers keyboard. Try both.
>
> The Javarosa code can be found here.https://bitbucket.org/javarosa/javarosa/src/. Grep in the core
> directory. I don't remember where I stuck the regex code :)
>
> Yaw
>
>
>
>
>
>
>
> On Sat, Feb 4, 2012 at 12:04, Asim Fayaz wrote:
> > I've placed a regex based constraint on a string fied to get a serial
> > number. It's supposed to be a 10 digit string. Here's the format I'm
> > using:
>
> > constraint="regex(., '^\d\d\d\d\d\d\d\d\d\d$')"
>
> > It ensures that the string is at least 10 digits long. However, it
> > also accepts strings longer than 10 digits. I've tried looking into
> > the ODK Collect code but this seems to be part of the javarosa
> > specifications that aren't included in the source. Please help.
>
> > Asim
>
> > --
> > Post: opendatakit@googlegroups.com
> > Unsubscribe: opendatakit+unsubscribe@googlegroups.com
> > Options:http://groups.google.com/group/opendatakit?hl=en
I am developing a questionnaire that captures names of places and people. As a way of ensuring correctness and/or validity of the entries, I have decided to use Regular Expressions to define what characters are acceptable.
For my scenario, I would like to allowa single quote (') in the names, for names such as O'Brian.
I am using XLSForm and the contraint would be something like regex(, '^[\p{L} .'-]+$').
When I try to convert that, I get an error and I think it's becasue of the single quote in the middle. I tried using double quotes but kept getting the same error.
I need help with defining such a regular expression in XLSForm.
^[0-9]{10,}$ will match only numbers greater than 10 digits in length.
Also, in the input control XML, use appearance="numbers" to allow for a
string field with a numbers keyboard. Try both.
I've placed a regex based constraint on a string fied to get a serial
number. It's supposed to be a 10 digit string. Here's the format I'm
using:
constraint="regex(., '^\d\d\d\d\d\d\d\d\d\d$')"
It ensures that the string is at least 10 digits long. However, it
also accepts strings longer than 10 digits. I've tried looking into
the ODK Collect code but this seems to be part of the javarosa
specifications that aren't included in the source. Please help.
As to the problem at hand, pyxform doesn't support quotes. You'll have
to edit the XML and type it there, and even then, you might have to do
some trial and error to get it to behave well.
I am developing a questionnaire that captures names of places and people. As a way of ensuring correctness and/or validity of the entries, I have decided to use Regular Expressions to define what characters are acceptable.
For my scenario, I would like to allowa single quote (') in the names, for names such as O'Brian.
I am using XLSForm and the contraint would be something like regex(, '^[\p{L} .'-]+$').
When I try to convert that, I get an error and I think it's becasue of the single quote in the middle. I tried using double quotes but kept getting the same error.
I need help with defining such a regular expression in XLSForm.
I have tried ^[0-9]{10}$ (type is string) to match exactly 10 digits and it works fine except when the first digit is zero. Have tried on version 1.1.7 ard 1.2 and same result.
Some people, when confronted with a problem, think "I know, I'll use
regular expressions." Now they have two problems.
-- Jamie Zawinski
Don't constrain names. It's more trouble than it's worth and your
regex will certainly not capture all the punctuation or random
characters that names can contain. See
As to the problem at hand, pyxform doesn't support quotes. You'll have
to edit the XML and type it there, and even then, you might have to do
some trial and error to get it to behave well.
I am developing a questionnaire that captures names of places and
people. As a way of ensuring correctness and/or validity of the entries, I
have decided to use Regular Expressions to define what characters are
acceptable.
For my scenario, I would like to allowa single quote (') in the names,
for names such as O'Brian.
I am using XLSForm and the contraint would be something like regex(,
'^[\p{L} .'-]+$').
When I try to convert that, I get an error and I think it's becasue of
the single quote in the middle. I tried using double quotes but kept
getting the same error.
I need help with defining such a regular expression in XLSForm.
Confirmed that this isn't working. I've filed a bug at http://code.google.com/p/opendatakit/issues/detail?id=546. Star it to
follow updates. This should be an easy fix, but might take sometime to
get it back into the the shipping version of Collect.
Until then, ^[0-9]{1}[0-9]{9}$ works for me. Can you try it?
···
On Tue, Mar 20, 2012 at 06:14, wrote:
> Yaw,
>
> I have tried ^[0-9]{10}$ (type is string) to match exactly 10 digits and it works fine except when the first digit is zero. Have tried on version 1.1.7 ard 1.2 and same result.
>
> Methu.
>
> --
> Post: opendatakit@googlegroups.com
> Unsubscribe: opendatakit+unsubscribe@googlegroups.com
> Options: http://groups.google.com/group/opendatakit?hl=en
Integers in ODK are restricted to 9 digits. To get around this, make
field a string, but give it an appearance=number in the , and
it'll restrict input to numbers plus a few other characters (+.,-). It
should also default to the number-keyboard for the on-screen keyboard.
···
---------- Forwarded message ----------
Date: Wed, May 23, 2012 at 12:16 AM
Subject: Re: Regex constraint
I am using the latest version of Collect (1.1.7) from the Android
market and am still trying to record a 10 digit phone number starting
with a 0 (see previous thread http://groups.google.com/group/opendatakit/browse_thread/thread/3298bd82b3bf7d50/0ab94b8af601c63b?lnk=gst&q=constraint+#0ab94b8af601c63b).
As with the OP in this thread, the problem seemed to be due to
starting with a 0, but I just removed the regex constraint and the
number was limited to 9 digits! This must be the default behaviour,
but is there any way to over-ride it. Tried using your expression
below, but that also failed.
9]
{9})$" jr:constraintMsg="Telephone number must have 10 digits"/>
Seems very strange that all integers are limited to 9 digits, or maybe
it should be a different type?
I am using the latest version of Collect (1.1.7) from the Android
market and am still trying to record a 10 digit phone number starting
with a 0 (see previous thread http://groups.google.com/group/opendatakit/browse_thread/thread/3298bd82b3bf7d50/0ab94b8af601c63b?lnk=gst&=constraint+#0ab94b8af601c63b).
As with the OP in this thread, the problem seemed to be due to
starting with a 0, but I just removed the regex constraint and the
number was limited to 9 digits! This must be the default behaviour,
but is there any way to over-ride it. Tried using Yaw's expression
(below), but that also failed.
Seems very strange that all integers are limited to 9 digits, or maybe
it should be a different type?
You can always define this to be a string with an appearance of number.
That should keep the leading-zero-removal from happening. I.e.,
<bind type="string".../>
<input appearance="number" ...>
Mitch
···
On Sun, May 27, 2012 at 10:24 PM, dj_bridges wrote:
I am using the latest version of Collect (1.1.7) from the Android
market and am still trying to record a 10 digit phone number starting
with a 0 (see previous thread
It would seem that this would be simple to fix, but for whatever
reason, the form is not behaving as it apparently should. Here is a
link to a pared down version of the form: http://pastebin.com/qLX4rrhV
I have tried every combination of type="int" / type="string",
appearance="number" and many different regex, but none allow 10 and
only 10 digits to be entered. If type="string" then the alphanumeric
keyboard appears rather than the numeric one and letters can be
entered.
Does anyone have a form with the desired behaviour so that I can see
if it is something on my phones (tested it on two phones running 2.2
and 2.3 Android versions so far)?
Integer values are restricted to 9 digits or less, so you will need to use
a string to hold 10-digit or larger numbers. Whenever you use an int or
decimal bind, the field value is first interpreted as number and stored
internally as such.The constraint then converts that internal number to a
string (omitting leading zeros), and applies the regex to that string. So
if it is an int or decimal bind, you can only test for up to 9 digits,
because of the removal of the leading zeros, and the 9-digit limit on the
size of the number.
The string bind retains all the leading zeros, because it is never
interpreted as a number. The regex form is defined here: http://jakarta.apache.org/regexp/apidocs/
Mitch
···
On Tue, May 29, 2012 at 1:40 AM, dj_bridges wrote:
It would seem that this would be simple to fix, but for whatever
reason, the form is not behaving as it apparently should. Here is a
link to a pared down version of the form: http://pastebin.com/qLX4rrhV
I have tried every combination of type="int" / type="string",
appearance="number" and many different regex, but none allow 10 and
only 10 digits to be entered. If type="string" then the alphanumeric
keyboard appears rather than the numeric one and letters can be
entered.
Does anyone have a form with the desired behaviour so that I can see
if it is something on my phones (tested it on two phones running 2.2
and 2.3 Android versions so far)?
Also, be sure to get the latest 1.2RC1 or 1.1.7 build, as there was a
different bug fixed in this area that likely caused some of the earlier
problems Asim reported.
Mitch
···
On Tue, May 29, 2012 at 11:13 AM, Mitch S wrote:
Sorry, the appearance should be "numbers", not "number".
The form was confusing because which entry was reporting the error message
was unclear (it could have referred to either field).
Integer values are restricted to 9 digits or less, so you will need to use
a string to hold 10-digit or larger numbers. Whenever you use an int or
decimal bind, the field value is first interpreted as number and stored
internally as such.The constraint then converts that internal number to a
string (omitting leading zeros), and applies the regex to that string. So
if it is an int or decimal bind, you can only test for up to 9 digits,
because of the removal of the leading zeros, and the 9-digit limit on the
size of the number.
The string bind retains all the leading zeros, because it is never
interpreted as a number. The regex form is defined here: http://jakarta.apache.org/regexp/apidocs/
It would seem that this would be simple to fix, but for whatever
reason, the form is not behaving as it apparently should. Here is a
link to a pared down version of the form: http://pastebin.com/qLX4rrhV
I have tried every combination of type="int" / type="string",
appearance="number" and many different regex, but none allow 10 and
only 10 digits to be entered. If type="string" then the alphanumeric
keyboard appears rather than the numeric one and letters can be
entered.
Does anyone have a form with the desired behaviour so that I can see
if it is something on my phones (tested it on two phones running 2.2
and 2.3 Android versions so far)?
Thanks so much for the clarifications and small modifications.
Everything appears to be working perfectly now with the latest Collect
version from the market!