2020-01-12 19:15:08 +08:00
|
|
|
exports.randomChar = function(l) {
|
2025-10-20 19:24:01 +08:00
|
|
|
let x = "0123456789qwertyuioplkjhgfdsazxcvbnm";
|
|
|
|
|
let tmp = "";
|
|
|
|
|
for(let i = 0;i < l; i++) {
|
2020-01-12 19:15:08 +08:00
|
|
|
tmp += x.charAt(Math.ceil(Math.random()*100000000)%x.length);
|
|
|
|
|
}
|
|
|
|
|
return tmp;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.randomNumber = function(l) {
|
2025-10-20 19:24:01 +08:00
|
|
|
let x = "0123456789";
|
|
|
|
|
let tmp = "";
|
|
|
|
|
for(let i = 0;i < l; i++) {
|
2020-01-12 19:15:08 +08:00
|
|
|
tmp += x.charAt(Math.ceil(Math.random()*100000000)%x.length);
|
|
|
|
|
}
|
|
|
|
|
return tmp;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.validateEmail = function (email) {
|
2025-10-20 19:24:01 +08:00
|
|
|
let re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
2020-01-12 19:15:08 +08:00
|
|
|
return re.test(email);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function rnd() {
|
2025-10-20 19:24:01 +08:00
|
|
|
let today = new Date();
|
|
|
|
|
let seed = today.getTime();
|
2020-01-12 19:15:08 +08:00
|
|
|
seed = (seed * 9301 + 49297) % 233280;
|
|
|
|
|
return seed / (233280.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cr(number) {
|
|
|
|
|
return Math.ceil(rnd() * number);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isNumber() {
|
2025-10-20 19:24:01 +08:00
|
|
|
let r = /^[0-9]*[1-9][0-9]*$/;
|
2020-01-12 19:15:08 +08:00
|
|
|
return r.test(str);
|
|
|
|
|
}
|