I would like to validate point in a two-dimensional rectangular Cartesian coordinate. I found following regular expression solution on stackoverflow ^(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$
. Another solution is using little PHP controls:
$xy = explode(",", "-3,3");
$return = array(0,0);
if(is_array($xy) && count($xy) == 2) {
$return = $xy;
foreach($xy as $digit) {
if(!is_numeric($digit)) {
$return = array(0,0);
break;
}
}
}
Although, seconds solution is "larger", I prefer this for readability. What elements should I use to make the right choice between those two solutions?