Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an HTML page with a Form validation using JSP. A HTML file and a JSP file

ID: 3667639 • Letter: C

Question

Create an HTML page with a Form validation using JSP. A HTML file and a JSP file is required.

The fields have the following properties: - user first name (text) - user last name (text) - user username (text- no more than 10 character with validation) - user password (password - at least 6 characters with validation) - user retyped password (password) - user address (text) - user email (text – with validation) - clear form button and a submit button

Functionality: when you press submit the form is validated for empty field.

Explanation / Answer

1.Validate the name and password

<script>  

function validateform(){  

var name=document.myform.name.value;  

var password=document.myform.password.value;  

if (name==null || name==""){

  alert("Name can't be blank");  

return false;  

}else if(password.length<6){  

  alert("Password must be at least 6 characters long.");

return false;

  } }

</script>  

<body>  

<form name="myform" method="post" action="abc.jsp" >  

Name: <input type="text" name="name"><br/>  

Password: <input type="password" name="password"><br/>  

<input type="submit" value="register">  

</form>  

2.JavaScript Retype Password Validation

<script type="text/javascript">  

function matchpass(){  

var firstpassword=document.f1.password.value;  

var secondpassword=document.f1.password2.value;  

  if(firstpassword==secondpassword){

return true;  

}  

else{  

alert("password must be same!");  

return false;  

} }

</script>  

<form name="f1" action="register.jsp">  

Password:<input type="password" name="password" /><br/>  

Re-enter Password:<input type="password" name="password2"/><br/>  

<input type="submit">  

</form>  

3.JavaScript Number Validation

Let's validate the textfield for numeric value only. Here, we are using isNaN() function.

<script>  

function validate(){  

var num=document.myform.num.value;  

if (isNaN(num)){  

document.getElementById("numloc").innerHTML="Enter Numeric value only";  

  return false;  

}else{  

  return true;  

  } }

</script>  

<form name="myform" >  

Number: <input type="text" name="num"><span id="numloc"></span><br/>  

<input type="submit" value="submit">  

</form>  

4.JavaScript email validation

<script>  

function validateemail()  

{  

var x=document.myform.email.value;  

var atposition=x.indexOf("@");  

var dotposition=x.lastIndexOf(".");  

if (atposition<1 || dotposition<atposition+2 || dotposition+2>=x.length){  

alert("Please enter a valid e-mail address atpostion:"+atposition+" dotposition:"+dotposition);  

return false;  

  } }

</script>  

<body>  

<form name="myform"  method="post" action="#">  

Email: <input type="text" name="email"><br/>    

<input type="submit" value="register">  

</form>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote