validation - Error in validating Latitude and Longitude in php -


i trying validate latitude , longitude using function.

this function using:

// function validate latitude function isvalidlatitude($latitude){     if (preg_match("/^-?([1-8]?[1-9]|[1-9]0)\.{1}\d{1,6}$/", $latitude)) {             return true;     } else {             return false;     } } 

this how call it:

// check "latitude":     if (!empty( $_post['geolat'])) {         if (isvalidlatitude($_post['geolat'])) {         $_session['geolat'] = $_post['geolat'];      } else {         $error_alert[] = "find location correctly";     }        } else {     $error_alert[] = "you didn't find locaiton on google map"; }    

but not working me. going :

$error_alert[] = "find location correctly"; 

my $_post array looks this:

array (     [rest_location] => colombo     [geolat] => 6.929677319820927     [geolng] => 79.86519121166998     [submitted] => true ) 1 

can tell me wrong this?

thank you.

your post value -

[geolat] => 6.929677319820927 

doesn't match against regex you've used.(it allows 1 6 digits after decimal point)

can either change regex -

^-?([1-8]?[1-9]|[1-9]0)\.{1}\d{1,20}$                                  ^^ changed 6 20 

or
change geolat value round upto 6 digits after decimal-

$_post['geolat']) = floor($_post['geolat']) * 1000000)/1000000 

Comments