-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkerror.js
63 lines (57 loc) · 1.7 KB
/
checkerror.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
document.getElementById('submit').addEventListener('click',()=>{
var obj={
//Getting inputs
userNam:document.getElementById('info').value,
phoneNum:document.getElementById('phonenumber').value,
perAd:document.getElementById('address1').value,
temAd:document.getElementById('address2').value,
emai:document.getElementById('email').value};
//Checking error
var access=function()
{
if(obj.userNam.length<3)
{
alert('Invalid name!!!');
return false;
}
else if(obj.phoneNum.length<10)
{
alert('Number should be 10 character long');
return false;
}
else if(obj.perAd.length<3)
{
alert('Wrong permanent address');
return false;
}
else if(obj.temAd.length<=3)
{
alert('Wrong temporary address');
return false;
}
else{
alert('Right!!!');
return true;
}
}
var dataStorage=[];
//Saving and displaying only if all the box are filled
if(access()===true){
var stg=JSON.stringify(obj); //converting to string
localStorage.setItem('datas',stg);
var conv=JSON.parse(stg); //converting to object
dataStorage.push(localStorage.getItem(conv));
console.log(conv);
var upper=999;
var lower=100;
var numBer=obj.perAd+'-'+ (Math.floor(Math.random()*(upper-lower+1))+lower);
console.log(numBer);
console.log(dataStorage);
//Setting everything to new one
document.getElementById('info').value='';
document.getElementById('phonenumber').value='';
document.getElementById('address1').value='';
document.getElementById('address2').value='';
document.getElementById('email').value='';
}
});