-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
77 lines (75 loc) · 2.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const form = document.getElementById("form");
form.addEventListener('submit',(e)=>{
(e).preventDefault();
});
function validate(){
let name = document.getElementById("name").value.trim();
let phone = document.getElementById("phone_num").value.trim();
let email = document.getElementById("email").value.trim();
let pass = document.getElementById("passcode").value.trim();
localStorage.setItem("name",name);
localStorage.setItem("phone",phone);
localStorage.setItem("email",email);
localStorage.setItem("password",pass);
let flag=0;
name = name.toUpperCase();
let len = name.length;
let len2 = pass.length;
let reg1=/^[A-Z][A-Z\s]*$/;
let reg2 = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
let reg3 = /^[7-9]{1}[0-9]{9}$/;
//name should be only alphabets and of max length 30
if(name != "" && phone!= "" && email != "" && pass!= "")
{
if(len<=30){
if(reg1.test(name) === true){
flag=flag+1;
}
else{
alert("Enter a valid name");
}
}
else{
alert("Enter a valid name");
}
//validity of email
if(reg2.test(email) == true){
flag += 1;
}
else{
alert("Enter valid email");
}
//validity of phone number
if(reg3.test(phone) == true){
flag += 1;
}
else{
alert("Enter valid phone number");
}
//passsword validation
if(len2>=8){
flag += 1;
}
else{
alert("Enter a password of 8 characters");
}
}
if(flag==4){
alert("Form submitted successfully");
window.location.href = "login.html";
}
}
function login(){
let email = localStorage.getItem("email");
let passcode = localStorage.getItem("password");
let email_pass = document.getElementById("email_add").value.trim();
let password = document.getElementById("pass").value.trim();
if( email_pass != "" && password != ""){
if(email_pass == email && password == passcode){
window.location.href = "payment.html";
}
else{
alert("enter valid email ID/password");
}
}
}