not empty validation JavaScript JS

Not empty or blank field validation is used to check whether anything is entered in a given field or not. It will check for null and zero-length strings.

Example:

<!DOCTYPE html>
<html lang="en">
<head>
<script>
function notEmptyCheck(name)
{
if (name.value.length == 0)
{
alert("Name can not be empty.");
return false;
}
return true;
}
</script>
</head>
<body>
<div>
<h2>JavaScript Not Empty Validation</h2>
<form name="form1" action="#">
Name: <input type='text' name='name'/></br></br>
<input type="submit" name="submit" value="Submit" onclick="notEmptyCheck(document.form1.name)"/>
</form>
</div>
</body>
</html>