I’m letting users enter GPS values through a form, they all have the same form, some examples:
49.082243,19.302628
48.234142,19.200423
49.002524,19.312578
I want to check the entered value using PHP (using preg_match(), I guess), but as I’m not good in regex expressions (oh, dumb me, I should finally learn it, I know), I don’t know how to write the expression.
Obviously it should be:
2x (numbers), 1x (dot), 6x (numbers), 1x (comma), 2x (numbers), 1x (dot), 6x (numbers)
Any suggestions how to write this in regex?
Something like:
^anchors at the start of input-?allows for, but does not require, a negative sign\d{1,2}requires 1 or 2 decimal digits\.requires a decimal point\d{6}requires exactly 6 decimal digits,matches a single comma$anchors at the end of inputI have included capturing parentheses to allow you to extract the individual coordinates. Feel free to omit them if you don’t need that.
All-around useful regex reference: http://www.regular-expressions.info/reference.html