js 通用的 utils

时间:2020-05-22 17:09:32   收藏:0   阅读:58

 

 

技术图片
// 验证手机号码
export function isMobile(s) {
    return /^1[0-9]{10}$/.test(s)
}
验证手机号码

 

技术图片
// 验证邮箱
export function isEmail(email) {
    return /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/.test(email)
}
验证邮箱

 

技术图片
export function returnTime(e) {
    var thisTime = Date.parse(new Date()); //当前的时间戳
    var startTime = Date.parse(e); //发布的时间戳
    let past = parseInt(parseInt(parseInt((thisTime - startTime) / 1000) / 60) / 60); //过去了多久
    return past < 1 ? ‘刚刚‘ : past < 24 ? past + "小时前" : e.substring(0, 11)
}
时间转换:过去了多久

 

技术图片
//万位数转换
export function returnWan(e) {
    if (e > 10000) {
        return Math.floor(e / 10000 * 100) / 100 + "万" + "+"
    }
    return e
}
万位数转换

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!