var fmtDate = /^(\d{1,4})-(\d{1,2})-(\d{1,2})\b/; // 日期
//var fmtEmail = /^[\w-\.]+@[\w-]+\.[\w-]+$/; // Email
var fmtEmail = /^[\w-\.]+@[\w-]+(\.[\w-]+)+$/; // Email
var fmtMobilePhone = /^13\d{9}$/; // 移动电话
var fmtTelephone = /^(0\d{2,3}-?)?\d{7,8}$/; // 国内固定电话
var fmtZip = /^[1-9]\d{5}$/; // 邮政编码
var fmtTrim = /^[\s ]*([\S]*)[\s ]*$/; // trim
var fmtTime = /^(\d{1,2})\:(\d{1,2})$/;
var fmtQuote = /\'/g;
/** 仅能判断字符串去除空格后是否为空,因为字符串中间有空格或者其他字符时返回整个字符串 */
String.prototype.trim = function (){
return this.replace(fmtTrim, '$1');
}
/** 将 ' 替换成 '' ,SQL 语句用 --还没有用上 */
String.prototype.quote = function (){
return this.replace(fmtQuote, '\'\'');
}
/** 字节长度 */
String.prototype.byteLen = function (){
var count = 0, idx = 0;
while (idx < this.length) count += this.charCodeAt(idx++) > 0xFF ? 2 : 1;
return count;
}
/** 返回日期的毫秒数(符合fmtDate描述的日期) 日期格式yyyy-mm-dd */
function parseDate(date){
return Date.parse(date.replace(fmtDate, '$2/$3/$1'));
}
/** 比较日期 */
function compareDate(date1, date2){
return parseDate(date1) - parseDate(date2);
}
/** 是否日期(严格判断用isValidDate()) */
function isDate(date){
return fmtDate.test(date);
}
/** 是否时间 hh:mm */
function isTime(strTime){
return fmtTime.test(strTime) && RegExp.$1 < 60 && RegExp.$2 < 60;
}
/** 是否Email */
function isEmail(email){
return fmtEmail.test(email);
}
/** 是否手机号码(13xxxxxxxxx) */
function isMobilePhone(mobilePhone){
return fmtMobilePhone.test(mobilePhone);
}
/** 是否固定电话 */
function isTelephone(telephone){
return fmtTelephone.test(telephone);
}
/** 固定电话或者移动电话 */
function isTel(tel){
return isMobilePhone(tel) || isTelephone(tel);
}
/** 邮政编码 */
function isZip(zip){
return fmtZip.test(zip);
}
/** 数字域,但允许为空 */
function numField(field){
with (field){
if (value.trim() != '' && isNaN(value)){
alert('请输入数字!'); focus(); select(); return false;
} else return true;
}
}
/** 电话域 */
function telField(field){
with (field){
if (value.trim() != '' && !isTel(value)){
alert('请输入有效电话号码!'); focus(); select(); return false;
} else return true;
}
}
/** 邮政编码域 */
function zipField(field){
with (field){
if (value.trim() != '' && !isZip(value)){
alert('请输入有效邮政编码!'); focus(); select(); return false;
} else return true;
}
}
表单校验 check.js(1)
转载上一篇:表单校验 check.js(2)
下一篇:校验表单的正则表达式
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
javascript/JS表单的校验
对于javaWeb往往需要注册,但是对于注册往往需要许多条件限制,比如用户名、密码、邮箱等等,下面小编就来整
字符串 下划线 javascript -
四、JS之表单校验
详情参见Jquery Validate 相关参数及常用的自定义验证规则
自定义 表单验证 表单校验 -
表单校验案例
14-表单校验案例-案例效果和分析15-表单校验案例-案例的实现<!DOCTYPE html><html lang="en"><head>
表单校验 用户名 html 内置对象 css