Validation for latitude and longitude values using ng-pattern

NIKHIL K A picture NIKHIL K A · Jun 1, 2016 · Viewed 7.7k times · Source

I have used ng-pattern

/^[0-9]{1,7}(\.[0-9]+)?$/

for validate latitude and longitude values, but this pattern is not allowing me to enter negative values.

Latitude and longitude values contains negative and decimal values Can you please suggest me one good ng-pattern for my requirements.

Example values are given below

234.546655, 3.5766876, 12345.766566

I need validation for this type values. It should allow negative,positive,decimal and all numbers

Answer

Colin Fiat picture Colin Fiat · Jun 1, 2016

This is a complete answer: https://stackoverflow.com/a/18690202/6359058

For your example: [-+]? is required for either - or +

/^[-+]?[0-9]{1,7}(\.[0-9]+)?$/