a regex question. validating decimal values that fall within a postive or negative range

Hi, I am writing a couple of regex values to validate for valid longitude values that should fall within a specific range , and so far i got the general syntax ok for longitudes , my regex is as follows: [-]?3[1-7]*[.]{0,1}[0-9]{0,6} i.e an optional negative sign followed by a number in the range 31-37 , followed by an optional decimal point, and if there is a decimal point then a set of numeric character to a max of 6 characters. When i run the regex on some test values i get the following results -31.00000000 TRUE 31.00000000 TRUE -37.999999999 TRUE 37.999999999 TRUE -36.744uiu82 TRUE ( but should be false.; it truncates the characters to return a true on -36.744) 36.744uiu82 TRUE ( but should be false.; it truncates the characters to return a true on 36.744) -3sers6.744uiu82 TRUE ( but should be false.; it truncates the characters to return a true on -3) 3sers6.744uiu82 TRUE ( but should be false.; it truncates the characters to return a true on 3) 28.90909 FALSE (does not fall in range) -28.90909 FALSE (does not fall in range) My problem is with the values in the text highlighted . Obviously 36.uoiuy5656 is not a valid value since in its entirety it contains a mix of non-numeric values What am i doing wrong or missing here? I am not well versed with greedy or backreferenced syntax. Any assitance would be greatly appreciated. Kind regards Kiti Chigiri

What you need to add to your regex expression is boundary matchers to make sure it macthes the whole input string. Something like this ^[-]?3[1-7]*[.]{0,1}[0-9]{0,6}$ On Wed, Oct 26, 2011 at 10:44 AM, Kiti Chigiri <kiti.chigiri@gmail.com>wrote:
Hi,
I am writing a couple of regex values to validate for valid longitude values that should fall within a specific range , and so far i got the general syntax ok
for longitudes , my regex is as follows: [-]?3[1-7]*[.]{0,1}[0-9]{0,6}
i.e an optional negative sign followed by a number in the range 31-37 , followed by an optional decimal point, and if there is a decimal point then a set of numeric character to a max of 6 characters.
When i run the regex on some test values i get the following results -31.00000000 TRUE 31.00000000 TRUE -37.999999999 TRUE 37.999999999 TRUE -36.744uiu82 TRUE ( but should be false.; it truncates the characters to return a true on -36.744) 36.744uiu82 TRUE ( but should be false.; it truncates the characters to return a true on 36.744) -3sers6.744uiu82 TRUE ( but should be false.; it truncates the characters to return a true on -3) 3sers6.744uiu82 TRUE ( but should be false.; it truncates the characters to return a true on 3) 28.90909 FALSE (does not fall in range) -28.90909 FALSE (does not fall in range)
My problem is with the values in the text highlighted . Obviously 36.uoiuy5656 is not a valid value since in its entirety it contains a mix of non-numeric values
What am i doing wrong or missing here? I am not well versed with greedy or backreferenced syntax. Any assitance would be greatly appreciated.
Kind regards
Kiti Chigiri
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
-- Solomon Kariri, Software Developer, Cell: +254736 729 450 Skype: solomonkariri

Thanks Solomon, I tested the regex that you provided using the same dataset and it returned a false on all the params as it was returning a false on a test value like -37.-09099980980980 . i removed the negation (^) and added a named capture group to truncate the expected value. Basically i modified the regex to be as follows: (?<val>[-]?3[1-7]*[.]{0,1}[0-9]{0,6})[0-9]*$ the required value is found in the named capture group "val" Thanks to Solomon and Josh Regards On Wed, Oct 26, 2011 at 10:52 AM, solomon kariri <solomonkariri@gmail.com>wrote:
What you need to add to your regex expression is boundary matchers to make sure it macthes the whole input string. Something like this ^[-]?3[1-7]*[.]{0,1}[0-9]{0,6}$
On Wed, Oct 26, 2011 at 10:44 AM, Kiti Chigiri <kiti.chigiri@gmail.com>wrote:
Hi,
I am writing a couple of regex values to validate for valid longitude values that should fall within a specific range , and so far i got the general syntax ok
for longitudes , my regex is as follows: [-]?3[1-7]*[.]{0,1}[0-9]{0,6}
i.e an optional negative sign followed by a number in the range 31-37 , followed by an optional decimal point, and if there is a decimal point then a set of numeric character to a max of 6 characters.
When i run the regex on some test values i get the following results -31.00000000 TRUE 31.00000000 TRUE -37.999999999 TRUE 37.999999999 TRUE -36.744uiu82 TRUE ( but should be false.; it truncates the characters to return a true on -36.744) 36.744uiu82 TRUE ( but should be false.; it truncates the characters to return a true on 36.744) -3sers6.744uiu82 TRUE ( but should be false.; it truncates the characters to return a true on -3) 3sers6.744uiu82 TRUE ( but should be false.; it truncates the characters to return a true on 3) 28.90909 FALSE (does not fall in range) -28.90909 FALSE (does not fall in range)
My problem is with the values in the text highlighted . Obviously 36.uoiuy5656 is not a valid value since in its entirety it contains a mix of non-numeric values
What am i doing wrong or missing here? I am not well versed with greedy or backreferenced syntax. Any assitance would be greatly appreciated.
Kind regards
Kiti Chigiri
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
-- Solomon Kariri,
Software Developer, Cell: +254736 729 450 Skype: solomonkariri
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
participants (2)
-
Kiti Chigiri
-
solomon kariri