diff --git a/src/lib/isLatLong.js b/src/lib/isLatLong.js index c4e622753..5fd89db2b 100644 --- a/src/lib/isLatLong.js +++ b/src/lib/isLatLong.js @@ -6,7 +6,7 @@ const lat = /^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/; const long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/; const latDMS = /^(([1-8]?\d)\D+([1-5]?\d|60)\D+([1-5]?\d|60)(\.\d+)?|90\D+0\D+0)\D+[NSns]?$/i; -const longDMS = /^\s*([1-7]?\d{1,2}\D+([1-5]?\d|60)\D+([1-5]?\d|60)(\.\d+)?|180\D+0\D+0)\D+[EWew]?$/i; +const longDMS = /^\s*((?:1[0-7]\d|\d{1,2})\D+([1-5]?\d|60)\D+([1-5]?\d|60)(\.\d+)?|180\D+0\D+0(?:\.0+)?)\D+[EWew]?$/i; const defaultLatLongOptions = { checkDMS: false, diff --git a/test/validators.test.js b/test/validators.test.js index 98d2a12ff..a3ae061e4 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -12856,6 +12856,36 @@ describe('Validators', () => { }); }); + it('should validate DMS longitude bounds', () => { + test({ + validator: 'isLatLong', + args: [{ checkDMS: true }], + valid: [ + '0° 0′ 0″ N, 0° 0′ 0″ E', + '40° 26′ 46″ N, 9° 58′ 56″ E', + '40° 26′ 46″ N, 99° 58′ 56″ W', + '40° 26′ 46″ N, 100° 58′ 56″ E', + '40° 26′ 46″ N, 170° 58′ 56″ W', + '40° 26′ 46″ N, 179° 59′ 59.999″ E', + '40°26′46″s,179°59′59.999″w', + '90° 0′ 0″ N, 180° 0′ 0″ E', + '90° 0′ 0″ S, 180° 0′ 0″ W', + '40° 26′ 46″ N, 180° 0′ 0.0″ E', + '40°26′46″s,180°0′0.000″w', + ], + invalid: [ + '40° 26′ 46″ N, 180° 1′ 0″ E', + '40° 26′ 46″ N, 180° 0′ 1″ W', + '40° 26′ 46″ N, 180° 0′ 0.001″ E', + '40° 26′ 46″ N, 181° 0′ 0″ E', + '40° 26′ 46″ N, 199° 0′ 0″ W', + '40° 26′ 46″ N, 200° 0′ 0″ E', + '40° 26′ 46″ N, 360° 0′ 0″ W', + '40°26′46″s,799°0′0″w', + ], + }); + }); + it('should validate postal code', () => { const fixtures = [ {