分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

jquery表单验证源码

发布时间:2023-09-06 01:08责任编辑:蔡小小关键词:暂无标签

/**
数据验证完整性
**/
$.fn.Validform = function () {
var Validatemsg = "";
var Validateflag = true;
$(this).find("[isvalid=yes]").each(function () {
var checkexpession = $(this).attr("checkexpession");
var errormsg = $(this).attr("errormsg");
if (checkexpession != undefined) {
if (errormsg == undefined) {
errormsg = "";
}
var value = $(this).val();
if ($(this).hasClass(‘ui-select‘)) {
value = $(this).attr(‘data-value‘);
}
switch (checkexpession) {
case "NotNull":
{
if (isNotNull(value)) {
Validatemsg = errormsg + "不能为空!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "Num":
{
if (!isInteger(value)) {
Validatemsg = errormsg + "必须为数字!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "NumOrNull":
{
if (!isIntegerOrNull(value)) {
Validatemsg = errormsg + "必须为数字!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "Email":
{
if (!isEmail(value)) {
Validatemsg = errormsg + "必须为E-mail格式!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "EmailOrNull":
{
if (!isEmailOrNull(value)) {
Validatemsg = errormsg + "必须为E-mail格式!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "EnglishStr":
{
if (!isEnglishStr(value)) {
Validatemsg = errormsg + "必须为字符串!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "EnglishStrOrNull":
{
if (!isEnglishStrOrNull(value)) {
Validatemsg = errormsg + "必须为字符串!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "LenNum":
{
if (!isLenNum(value, $(this).attr("length"))) {
Validatemsg = errormsg + "必须为" + $(this).attr("length") + "位数字!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "LenNumOrNull":
{
if (!isLenNumOrNull(value, $(this).attr("length"))) {
Validatemsg = errormsg + "必须为" + $(this).attr("length") + "位数字!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "LenStr":
{
if (!isLenStr(value, $(this).attr("length"))) {
Validatemsg = errormsg + "必须小于" + $(this).attr("length") + "位字符!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "LenStrOrNull":
{
if (!isLenStrOrNull(value, $(this).attr("length"))) {
Validatemsg = errormsg + "必须小于" + $(this).attr("length") + "位字符!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "Phone":
{
if (!isTelephone(value)) {
Validatemsg = errormsg + "必须电话格式!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "PhoneOrNull":
{
if (!isTelephoneOrNull(value)) {
Validatemsg = errormsg + "必须电话格式!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "Fax":
{
if (!isTelephoneOrNull(value)) {
Validatemsg = errormsg + "必须为传真格式!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "Mobile":
{
if (!isMobile(value)) {
Validatemsg = errormsg + "必须为手机格式!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "MobileOrNull":
{
if (!isMobileOrnull(value)) {
Validatemsg = errormsg + "必须为手机格式!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "MobileOrPhone":
{
if (!isMobileOrPhone(value)) {
Validatemsg = errormsg + "必须为电话格式或手机格式!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "MobileOrPhoneOrNull":
{
if (!isMobileOrPhoneOrNull(value)) {
Validatemsg = errormsg + "必须为电话格式或手机格式!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "Uri":
{
if (!isUri(value)) {
Validatemsg = errormsg + "必须为网址格式!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "UriOrNull":
{
if (!isUriOrnull(value)) {
Validatemsg = errormsg + "必须为网址格式!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "Equal":
{
if (!isEqual(value, $(this).attr("eqvalue"))) {
Validatemsg = errormsg + "不相等!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
break;
}
case "Date":
{
if (!isDate(value, $(this).attr("eqvalue"))) {
Validatemsg = errormsg + "必须为日期格式!\n";
Validateflag = false;
ValidationMessage($(this), Validatemsg); return false;
}
&nb

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved