Using regular expression to validate latitude and longitude coordinates then display error

前端 未结 3 1552
野的像风
野的像风 2020-12-17 00:39

How can I use a regular expression to validate the latitude and longitude for these text fields and display an error message?

 
3条回答
  •  攒了一身酷
    2020-12-17 01:11

    I used two different regexes for each value.

    Latiude Regex:

    const latRegex = /^-?([1-8]?[1-9]|[1-9]0)\.{1}\d{1,15}/g;

    Longitude Regex:

    const lngRegex = /^-?(([-+]?)([\d]{1,3})((\.)(\d+))?)/g;

提交回复
热议问题