Trying to use a number from a TextField

39 views
Skip to first unread message

rune-...@hotmail.com

unread,
Dec 12, 2013, 12:16:17 AM12/12/13
to codenameone...@googlegroups.com
I am trying to use a TextField for an input, then use only the numbers in the String.

My code looks like:


  String weightTotal = findTextField(c).getText();
     Matcher m = Pattern.compile("(?!=\\d\\.\\d\\.)([\\d.]+)").matcher(weightTotal);
              while (m.find()) {
                   double d = Double.parseDouble(m.group(1));
                   bags.setWeightTotal(d);
        }

But for some reason when it comes to compiling i am told "error: package java.util.regex does not exist
import java.util.regex.Matcher;" even tho i have in imported

Shai Almog

unread,
Dec 12, 2013, 1:54:35 AM12/12/13
to codenameone...@googlegroups.com, rune-...@hotmail.com
At this point in time we don't support the regex package from JavaSE.
We would like to introduce regex support in the future but it isn't builtin at the moment.
Steve implemented a regex library for Codename One though: https://github.com/shannah/cn1-regex

rune-...@hotmail.com

unread,
Dec 12, 2013, 2:12:21 AM12/12/13
to codenameone...@googlegroups.com, rune-...@hotmail.com
Okay thanks, are there any recommended solutions to this using the cno package?

Otherwise ill go ahread and implement the regex library

Shai Almog

unread,
Dec 12, 2013, 2:33:38 PM12/12/13
to codenameone...@googlegroups.com, rune-...@hotmail.com
We usually just define the constraint to numeric. Using the setConstraint flag.
A validate for number is actually pretty easy e.g. Integer.parseInt() will just throw an exception for an invalid number.
Reply all
Reply to author
Forward
0 new messages