0

Including if statement

I want my code below to return false and alert the user if they input a username that contains a space. How would you write it? if(username INCLUDES “ ”){ alert(“”) return false; } sorry if the title is phrased oddly, I didn’t know how to say it. https://code.sololearn.com/WtcEEjQV6VOf/?ref=app

19th Nov 2018, 2:00 AM
Yosharu
Yosharu - avatar
3 Respostas
+ 3
Try to add: if(username.indexOf(" ")!==-1) { alert("Username must not contain spacing."); return false; } https://code.sololearn.com/WWK6ulX3vhdX/?ref=app
19th Nov 2018, 2:14 AM
Calviղ
Calviղ - avatar
+ 1
Calviղ Very brilliant soln
19th Nov 2018, 2:20 AM
Dlite
Dlite - avatar
0
Try this: if(username.match(/\s/) != null){ alert("") return false; }
19th Nov 2018, 2:20 AM
Paul
Paul - avatar