@@ -106,26 +106,29 @@ export default class GeoPointEditor extends React.Component {
106
106
let value = e . target . value ;
107
107
108
108
if ( ! validateNumeric ( value ) ) {
109
- var values = value . split ( ',' ) ;
110
-
111
- if ( values . length == 2 ) {
112
- values = values . map ( val => val . trim ( ) ) ;
113
-
114
- if ( values [ 0 ] . length > 0 && validateNumeric ( values [ 0 ] ) ) {
115
-
116
- if ( values [ 1 ] . length <= 0 || ! validateNumeric ( values [ 1 ] ) ) {
117
- this . setState ( { latitude : values [ 0 ] } ) ;
118
- this . longitudeRef . current . focus ( ) ;
119
- this . longitudeRef . current . setSelectionRange ( 0 , String ( this . state . longitude ) . length ) ;
120
- return ;
121
- }
122
-
123
- if ( validateNumeric ( values [ 1 ] ) ) {
124
- this . setState ( { latitude : values [ 0 ] } ) ;
125
- this . setState ( { longitude : values [ 1 ] } ) ;
126
- this . longitudeRef . current . focus ( ) ;
127
- return ;
128
- }
109
+ const regex = / [ [ ( " ' ] ? (?< x > [ 0 - 9 . ] + ) [ " ' ] ? , [ " ' ] ? (?< y > [ 0 - 9 . ] + ) [ " ' ) \] ] ? / ;
110
+ const match = regex . exec ( value ) ;
111
+
112
+ if ( ! match ) {
113
+ return null ;
114
+ }
115
+
116
+ const values = [ match . groups . x , match . groups . y ] ;
117
+
118
+ if ( values [ 0 ] . length > 0 && validateNumeric ( values [ 0 ] ) ) {
119
+
120
+ if ( values [ 1 ] . length <= 0 || ! validateNumeric ( values [ 1 ] ) ) {
121
+ this . setState ( { latitude : values [ 0 ] } ) ;
122
+ this . longitudeRef . current . focus ( ) ;
123
+ this . longitudeRef . current . setSelectionRange ( 0 , String ( this . state . longitude ) . length ) ;
124
+ return ;
125
+ }
126
+
127
+ if ( validateNumeric ( values [ 1 ] ) ) {
128
+ this . setState ( { latitude : values [ 0 ] } ) ;
129
+ this . setState ( { longitude : values [ 1 ] } ) ;
130
+ this . longitudeRef . current . focus ( ) ;
131
+ return ;
129
132
}
130
133
}
131
134
}
0 commit comments