Skip to content

Commit 5bd42c5

Browse files
committed
validation for ipAddress added
1 parent 5bdfb62 commit 5bd42c5

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/js/views/components/ChoosingPage.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,14 @@ class ChoosingPage extends React.Component{
7979

8080
if (e.key.toLowerCase() == 'enter') {
8181

82-
let ipAddress = ipAddressInput.value;
82+
let ipAddress = ipAddressInput.value.trim();
83+
84+
if(!this.validateIP(ipAddress)){
85+
this.setState({
86+
addressInputHasError: true
87+
})
88+
return;
89+
}
8390

8491
this.setState({
8592
loadingShow: true
@@ -145,6 +152,17 @@ class ChoosingPage extends React.Component{
145152
})
146153
}
147154

155+
validateIP(ipAddress){
156+
157+
let ipAddressRegex = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,}$/;
158+
159+
if(ipAddressRegex.test(ipAddress)){
160+
return true;
161+
}
162+
return false;
163+
164+
}
165+
148166
render (){
149167
return (
150168
<div ref='choosingPage' className={`choosingPage ${this.state.choosingPageFadeOut ? 'choosingPage--fadeOut' : ''} ${this.state.choosingPageNone ? 'none' : ''}`}>

0 commit comments

Comments
 (0)