forked from crtr0/votr-part3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
31 lines (28 loc) · 795 Bytes
/
utils.js
File metadata and controls
31 lines (28 loc) · 795 Bytes
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
exports.smsify = function(str) {
if (str.length <= 160) { return str; }
else { return str.substr(0,157)+'...'; }
};
exports.initcap = function(str) {
return str.substring(0,1).toUpperCase() + str.substring(1);
};
exports.testint = function(str) {
var intRegex = /^\d+$/;
if(intRegex.test(str)) {
return true;
}
return false;
};
exports.formatPhone = function(phonenum) {
var regexObj = /^(?:\+?1[-. ]?)?(?:\(?([0-9]{3})\)?[-. ]?)?([0-9]{3})[-. ]?([0-9]{4})$/;
if (regexObj.test(phonenum)) {
var parts = phonenum.match(regexObj);
var phone = "";
if (parts[1]) { phone += "(" + parts[1] + ") "; }
phone += parts[2] + "-" + parts[3];
return phone;
}
else {
//invalid phone number
return phonenum;
}
};