<html>
<head>
<title>Js Validation</title>
</head>
<body>
<h2>JS Validation Form</h2>
<form name="userform">
<label for="user">Enter Username : </label>
<input type="text" name="user" id="user"><br><br>
<label for="password">Enter Password : </label>
<input type="password" name="password"
id="password"><br><br>
<input type="button" value="Submit" onclick="passUserForm()">
</form>
<script language="javascript">
function isValid(c) {
return /^[a-zA-Z]$/.test(c);
function passUserForm() {
var UserName = userform.user.value
if (UserName === "") {
alert("UserName must be Filled");
} else if (UserName.length < 6) {
alert("UserName must be at least 6 characters long!");
} else {
var valid = true;
for (var i = 0; i < UserName.length; i++) {
var c = UserName[i];
if (!isValid(c)) {
alert("UserName must be contains only alphabets");
valid = false;
break;
} if (valid) alert("Username accepted successfull");
var password = userform.password.value
if (password === "") {
alert("Password must be Filled");
} else if (password.length < 6) {
alert("Password must be at least 6 characters long!");
} else {
alert("Password accepted successfull");
} </script>
</body>
</html>