码迷,mamicode.com
首页 > Web开发 > 详细

js 表单验证

时间:2016-05-15 16:44:59      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

---恢复内容开始---

function checkUrl(url) {
    var re = /((http:\/\/|https:\/\/|ftps:\/\/)*([\w\u4e00-\u9fa5\-]+\.)+[\w\u4e00-\u9fa5\-]+(\/[\w\u4e00-\u9fa5\-\.\/?\@\%\!\&=\+\~\:\#\;\,]*)?)/ig;
    return re.test(url);
}

function checkPhone(num){
    return checkMobile(num) || checkTelephone(num);
}

function checkMobile(num){
    var re = /^1[3,4,5,7,8]\d{9}$/;
    return re.test(num);
}

function checkTelephone(num){
    var phoneReg = /(^\+86\.\d{3,5}\d{6,8}$)|(^\d{3}((\d-)|(-\d)|\d|-)\d{3}(\d|-|)\d{3}$)/;
    return phoneReg.test(num);
}

function checkEmail(email){
    var re = /^[&~#$*%\u4e00-\u9fa5_0-9a-z\-\.\/\\]+@([\u4e00-\u9fa5-a-z0-9]+\.){1,5}[\u4e00-\u9fa5a-z]+$/i;
    return re.test(email);
}

function checkDomain(domain){
    var re = /^([\u4e00-\u9fa5-a-z0-9]+\.){1,5}[\u4e00-\u9fa5a-z]+$/i;
    return re.test(domain);
}

function checkNumber(number){
    var re = /^[1-9]\d*$/;
    return number == 0 || re.test(number);
}

function checkDate(dateStr){
    var re = /^\d{4}(-)\d{2}(-)\d{2}$/;
    return re.test(dateStr);
}

function checkDateTime(dateTimestr){
    var re = /^\d{4}(-)\d{2}(-)\d{2}( )\d{2}:\d{2}:\d{2}$/;
    return re.test(dateTimestr);
}

function checkMoney(money){
    var re = /^(0|[1-9]\d*)(\.\d{1,2})?$/;
    return re.test(money);
}

 

---恢复内容结束---

js 表单验证

标签:

原文地址:http://www.cnblogs.com/rubekid/p/5495432.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!