-
Notifications
You must be signed in to change notification settings - Fork 0
/
strings.js
84 lines (76 loc) · 2.01 KB
/
strings.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
78
79
80
81
82
83
84
String.prototype.isAlpha = function() {
var alpha = true;
var Alpha = ["a","b","c","d","e","f","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
var explode = this.split("");
explode.forEach((item) => {
if(Alpha.indexOf(item.toLowerCase()) == -1){
alpha = false;
}
})
return alpha;
};
String.prototype.isNumeric = function() {
var alpha = true;
var Alpha = [1,2,3,4,5,6,7,8,9,0]
var explode = this.split("");
explode.forEach((item) => {
if(Alpha.indexOf(parseInt(item))==-1){
alpha = false;
}
})
return alpha;
};
String.prototype.isAlNum = function(){
// body...
var alphanumeric = false;
var Alpha = ["a","b","c","d","e","f","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
var Num = [1,2,3,4,5,6,7,8,9,0]
var explode = this.split("");
var alpha = false;
var num = false;
explode.forEach((item) => {
if(Alpha.indexOf(item.toLowerCase()) != -1){
alpha = true;
}
if(Num.indexOf(parseInt(item)) != -1){
num = true;
}
})
if(alpha && num){
alphanumeric =true;
}
console.log(alphanumeric)
return alphanumeric;
};
String.prototype.checkUpper = function() {
// body...
var explode = this.split("");
var containsUpper = false;
for (var i = explode.length - 1; i >= 0; i--) {
if(explode[i].toLowerCase() != explode[i]){
containsUpper = true;
}
}
console.log(containsUpper)
return containsUpper;
};
String.prototype.checkLower = function() {
// body...
var explode = this.split("");
var containsLower = false;
for (var i = explode.length - 1; i >= 0; i--) {
if(explode[i].toUpperCase() != explode[i]){
containsLower = true;
}
}
return containsLower;
};
String.prototype.fullAnalysis = function(){
var report = {}
report.alpha = this.isAlpha();
report.numeric = this.isNumeric();
report.alphanumeric = this.isAlNum();
report.containsLower = this.checkLower();
report.containsUpper = this.checkUpper();
return report
}