/
validate.js
39 lines (38 loc) · 1.31 KB
/
validate.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
S.validate = {
alphaNumeric: function (str, allowedChars) {
if (str != null && str != '') {
if (str.match(/^[a-zA-Z0-9]+$/)) { return true; }
if (allowedChars) {
if (Array.isArray(allowedChars)) {
var a = '';
for(var y = 0; y < str.length;y++){
a = str[y];
if (!a.match(/^[a-zA-Z0-9]+$/)) {
//check for allowed chars
var valid = false;
for (var x = 0; x < allowedChars.length; x++) {
if (a == allowedChars[x]) { valid = true; break; }
}
if (!valid) { return false; }
}
}
return true;
}
}
}
return false;
},
text: function (str, excludedChars) {
if (str != null && str != '') {
if (excludedChars) {
if (Array.isArray(excludedChars)) {
excludedChars.forEach(function (a) {
if (str.indexOf(a) >= 0) { return false;}
});
}
}
return true;
}
return false;
}
}