User input is stored in variable "a". "rightUsr" is a regex condition to check a required input.
How do I make it as if “a[user input] “ does not match it should alert "something went wrong" in if block, and in else block it should print "welcome!"
if(a.match(rightUsr) ){
document.write("Welcome")
}
else{
alert("something went wrong!")
}
CodePudding user response:
You have to use the logical NOT in JavaScript which is written as '!'. To implement your logic, the code is:
if(!a.match(rightUsr) ){
alert("something went wrong!")
}
else{
document.write("Welcome")
}
CodePudding user response:
if(!a.match(rightUsr) ){
alert("something went wrong!");
return;
}
document.write("Welcome")