-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
69 lines (61 loc) · 1.96 KB
/
Copy pathscript.js
File metadata and controls
69 lines (61 loc) · 1.96 KB
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
//===========================================================
// Function that checks the length of the string.
// return true if the string is more than 5 characters long.
// Otherwise, return false.
//===========================================================
function checkLength(str) {
return str.length > 5 ? true : false;
}
//===========================================================
// Function returns true if the string contains at least one
// lowercase letter and at least one uppercase letter.
// Otherwise, return false.
//===========================================================
function checkUpperLowerCase(str) {
let foundUpper = false;
let foundLower = false;
for (let i in str) {
if (
!foundUpper &&
isNaN(parseInt(str[i])) &&
str[i] === str[i].toUpperCase()
) {
foundUpper = true;
}
if (!foundLower && str[i] === str[i].toLowerCase()) {
foundLower = true;
}
}
return foundUpper && foundLower;
}
//===========================================================
// Function return true if the string has at least two numbers
// in it. Otherwise, return false.
//===========================================================
function checkForNumbers(str) {
let count = 0;
let found = false;
for (let i in str) {
if (!found && isNaN(str[i]) === false) {
count++;
found = count === 2 ? true : false;
}
}
return found;
}
//===========================================================
// Function validateUsername
//
//===========================================================
function validateUsername() {
let userName = document.forms['form']['uname'].value;
if (
checkLength(userName) &&
checkUpperLowerCase(userName) &&
checkForNumbers(userName)
) {
alert('Username accepted');
} else {
alert('Please eneter valid username');
}
}