1,判断手机号是否正确
function isPhone(tel) {
var telReg = !!tel.match(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);
return telReg;
}
返回值为true或者false,可以用if判断
举例:
if (isPhone(phone)) {
alert("手机号正确")
} else {
alert("手机号错误")
}
2,点击显示信息提示,一秒后自动消失
//消息提示
function showTips(content, time) {//content为提示内容。time为要显示的秒数
var windowWidth = $(window).width();
var tipsDiv = '<div class="tipsClass">' + content + '</div>';
$('body').append(tipsDiv);
$('div.tipsClass').css({
'left': '10%',//提示条离左边10%
'top': '5%',//提示条离顶部5%
'position': 'absolute',//位置固定
'padding': '3px 5px',//内部边框
'background': '#868686',//背景颜色
'font-size': '0.7rem',//字体大小
'margin': '0 auto',//文字居中
'text-align': 'center',
'width': '80%',//宽占80%,与left相呼应
'height': 'auto',//高度自动为文字高
'color': '#fff',//字体颜色
'opacity': '0.6',//显示透明度
'border-radius': '0.5rem'//圆角
}).show();
setTimeout(function() {
$('div.tipsClass').fadeOut();
}, (time * 1000));//显示时间
}
举例:
if (isPhone(phone)) {
alert("手机号正确")
} else {
showTips("手机号不正确", 1);
}
效果:
注:这些是我从网上找的,原作者不记得了