Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 102 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
@@ -1 +1,102 @@
/* Fill your code*/
const pattern = {
username: /^[a-z\d]{8,15}$/i,
email: /^([a-z\d\.-]+)@([a-z\d-]+)\.([a-z]{2,8})(\.[a-z]{2,8})?$/,
password: /^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*()]).{8,20}$/,
phone:/^\d{10}$/,
}

function formValidate(){

let name = document.forms["RegForm"]["Name"];
let nameInput = document.getElementById("name");
if(pattern.username.test(name.value)){
nameInput.textContent="";
}
else{
nameInput.textContent="Atleast 8 to 15 Character Required";
name.focus();
return false;
}


let address = document.forms["RegForm"]["Address"];
let addressInput = document.getElementById("address");
if(address.value==""){
addressInput.textContent="Address cannot be empty. Kindly fill ";
address.focus();
return false;
}
else{
addressInput.textContent="";
}


let email = document.forms["RegForm"]["EMail"];
let emailInput = document.getElementById("email");
if(email.value==""){
emailInput.textContent="Email cannot be empty. Kindly fill ";
email.focus();
return false;
}
else if(pattern.email.test(email.value)){
emailInput.textContent="";
}
else{
emailInput.textContent="Enter a vaild Email";
email.focus();
return false;
}


let password = document.forms["RegForm"]["Password"];
let passwordInput = document.getElementById("pwd");
if(password.value==""){
passwordInput.textContent="Kindly fill the Password";
password.focus();
return false;
}
else if(pattern.password.test(password.value)){
passwordInput.textContent="";
}
else{
passwordInput.textContent="password must contain 1 uppercase letter, 1 lowercase letter, atleast 1 number any Symbols";
password.focus();
return false;
}


let cpassword = document.forms["RegForm"]["cPassword"];
let cpasswordInput = document.getElementById("cpwd");
if(cpassword.value==""){
cpasswordInput.textContent="Kindly confirm your password";
cpassword.focus();
return false;
}
else if(cpassword.value==password.value){
cpasswordInput.textContent="";
}else{
cpasswordInput.textContent="Password and confirm password must be same";
cpassword.focus();
return false;
}


let phone = document.forms["RegForm"]["phone"];
let phoneInput = document.getElementById("phone");
let result = document.getElementById("result");
if(phone.value==""){
phoneInput.textContent="Kindly fill the phone number";
phone.focus();
return false;
}
else if(pattern.phone.test(phone.value)){
phoneInput.textContent="";
result.textContent="Regex validation Success";
return false;
}
else{
phoneInputs.textContent="Enter a valid 10 digit number";
phone.focus();
return false;
}
}
47 changes: 31 additions & 16 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,42 @@
</head>
<body>
<h2 style="text-align: center"> FORM VALIDATION</h2>
<form name="RegForm" action="/" onsubmit="return formValidate()" method="post">
<p>Name : <input type="text" name="Name"></p>
<label class="alert" id="name"></label><br>
<form name="RegForm" action="/" onsubmit="return formValidate()" method="post">
<table>
<tr>
<td><p>Name : <input type="text" name="Name" class="name" ></p></td>
<td><label class="alert" id="name">Atleast 8 to 15 Character Required</label></td><br>
</tr>

<p> Address : <input type="text" name="Address"> </p>
<label class="alert" id="address"></label><br>
<tr>
<td><p> Address : <input type="text" name="Address" class="address" ></p></td>
<td><label class="alert" id="address">Kindly fill Address field</label></td><br>
</tr>

<p>E-mail : <input type="text" name="EMail"></p>
<label class="alert" id="email"></label><br>
<tr>
<td><p>E-mail : <input type="text" name="EMail" class="mail"></p></td>
<td><label class="alert" id="email">Kindly fill Email field</label></td><br>
</tr>

<p>Password : <input type="password" name="Password"> </p>
<label class="alert" id="pwd"></label><br> <br>
<tr>
<td><p>Password : <input type="password" name="Password" class="password"></p></td>
<td><label class="alert" id="pwd">Kindly fill password field</label></td><br>
</tr>

<p>Confirm Password : <input type="password" name="cPassword"> </p>
<label class="alert" id="cpwd"></label><br> <br>

<p>Phone : <input type="number" name="phone"> </p>
<label class="alert" id="phone"></label><br> <br>

<p><input type="submit" value="Check" name="Submit"></p><br>
<tr>
<td><p>Confirm Password : <input type="password" name="cPassword" class="cpassword"></p></td>
<td><label class="alert" id="cpwd">Kindly fill this field</label></td><br>
</tr>

<tr>
<td><p>Phone : <input type="number" name="phone" class="phone"></p></td>
<td><label class="alert" id="phone">Kindly fill this field</label></td><br>
</tr>
<tr>
<td><p><input type="submit" value="Check" name="Submit" class="btn"></p></td><br>
</tr>
</table>
<p id="result"></p>
</form>
</body>
</html>
54 changes: 50 additions & 4 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,69 @@ div {

form {
margin: 0 auto;
width: 600px;
padding-top:2%;
width: 1200px;
text-align: center;
padding-top: 0%;
border: 1px Solid black;
background-color: aliceblue;
}

form>p{
display: flex;
flex-direction: row;
justify-content: center;
justify-content: flex-start;
padding-left: 120px;

}

input{
width: 300px;
margin-left: 2%;
width: 350px;
/* margin-left: 2%; */
float: inline-end;
}
.name{
margin-left: 20%;
}
.address{
margin-left: 18.75%;
}
.mail{
margin-left: 19.5%;
}
.password{
margin-left: 18%;
}
.cpassword{
margin-left: 10.75%;
}
.phone{
margin-left: 20%;
}
#result{
color: green;
font-weight: bold;
font-size: 20px;
text-align: center;
margin-left: 23%;
}
.btn{
margin-left: 33%;
height: 35px;
width: 175px;
font-size: larger;
font-weight: bold;
color: white;
background-color: orangered;
}
.alert{
color: red;
}
table{
width: 100%;
border-spacing: 0 25px;
}
td{
padding: 10px;
text-align: center;
}