Skip to content

Commit 1b9ec52

Browse files
separate js file for script include
1 parent a951106 commit 1b9ec52

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
var SmartFormValidationUtils = Class.create();
2+
SmartFormValidationUtils.prototype = {
3+
initialize: function() {},
4+
5+
isValidEmail: function(email) {
6+
if (!email) return false;
7+
var re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
8+
return re.test(email);
9+
},
10+
11+
isNumeric: function(val) {
12+
if (val === null || val === undefined) return false;
13+
return /^-?\d+(\.\d+)?$/.test(String(val));
14+
},
15+
16+
isFutureDate: function(dateStr) {
17+
if (!dateStr) return false;
18+
try {
19+
var date = new GlideDateTime(dateStr);
20+
var now = new GlideDateTime();
21+
return date.getNumericValue() > now.getNumericValue();
22+
} catch (e) {
23+
return false;
24+
}
25+
},
26+
27+
passwordStrengthScore: function(password) {
28+
if (!password) return 0;
29+
var score = 0;
30+
if (password.length >= 8) score++;
31+
if (/[A-Z]/.test(password)) score++;
32+
if (/[a-z]/.test(password)) score++;
33+
if (/[0-9]/.test(password)) score++;
34+
if (/[@$!%*#?&]/.test(password)) score++;
35+
return score; // 0-5
36+
},
37+
38+
normalizePhoneNumber: function(phone) {
39+
if (!phone) return '';
40+
return phone.replace(/[^0-9+]/g, '');
41+
},
42+
43+
// Simple IP address validator
44+
isValidIP: function(ip) {
45+
if (!ip) return false;
46+
var parts = ip.split('.');
47+
if (parts.length !== 4) return false;
48+
for (var i = 0; i < 4; i++) {
49+
var p = parseInt(parts[i], 10);
50+
if (isNaN(p) || p < 0 || p > 255) return false;
51+
}
52+
return true;
53+
},
54+
55+
type: 'SmartFormValidationUtils'
56+
};

0 commit comments

Comments
 (0)