Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i getting the user name to be entered but the first name and last name still submiiting which it not suppose to

What I have tried:

if(username == "" )
{
alert("please enter your username first.");
form_val.username.focus();
return false;

}
else if(username=='fname')
{
alert("username must not contain first name.");
form_val.username.focus();
return false;
}
else if(username=='lname'){
alert("user must not contain last name");
form_val.username.focus();
return false
}
Posted
Updated 17-May-23 17:55pm

1 solution

"==" is an absolute comparison: it requires the two strings on the left and right side of the operators to be identical.

To check if a string is anywhere inside another, use the JavaScript String includes() Method[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900