var hello = {};
hello.util = {
isEmail: function(s) { //邮箱
return /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(s) ? true : false;
},
isMobile: function(s) { //手机
return /^1[3|4|5|7|8][0-9]{9}$/.test(s) ? true : false;
},
isChinese : function(s){ //中文
return /^[\u4E00-\u9FA5]+$/.test(s) ? true : false;
}
}
使用方法:
if(hello.util.isEmail($('input[name="email"]').val())){
alert("格式正确");
}