javascript 关于表单的一些validation

validation-framework.js 客户端验证框架,用于客户端的验证是否为空 立即下载

******************************************************************************
*File name:validation.js
*Description:Referenced by the pages to validate the form values
*Author:Justin Wang 214026,Infosys
*Date:06-Oct-2005
******************************************************************************/


/******************************************************************************
*File name:checkLeapYear(nYear)
*Description:Check the input year if it is leap year.
*Input parameters:
* nYear- year to be checked
*Return:true on success ,false on no
******************************************************************************/
function checkLeapYear(nYear){
 if (nYear % 4 == 0)
  if (nYear % 100 == 0)
   if (nYear % 400 == 0)
    return true; 
   else
    return false;
  else
   return true;
 else
  return false;
}

/******************************************************************************
*File name:checkNum(element,value)
*Description:Check the input string only contains number.
*Input parameters:
* element - Name of the form element.
* value- The value of the element.
*Return:true on success ,false on error
******************************************************************************/
function checkNum(element,value){
 isOK=checkNull(element,value);
 if (!isOK){       
  return false;
 }
 str="1234567890";
 content=checkContent(value,"@NULL",str);
 if(content!=true){
  alert(element+" should be number only")
  return false;
 }
 return true;
}


/******************************************************************************
*File name:trim(value)
*Description:Delete the space between characters.
*Input parameters:
* value- input string.
*Return:String which contains no spaces
******************************************************************************/
function trim(value){
 var checkStr = value;
 var tempStr = '';
 var countBlank = 0;
 var countBlankEnd = 0;
 for(i = 0 ; i < checkStr.length ; i++){
  if (checkStr.charAt(i)!= ' '){
   break;
  }
  else{
   countBlank ++;
  }
 }

 for(i = checkStr.length - 1 ; i > 0 ; i--){
  if (checkStr.charAt(i) != ' '){
   break;
  }
  else{
   countBlankEnd ++;
  }
 }
 for(i = countBlank ; i<checkStr.length - countBlankEnd ; i++){
  tempStr += checkStr.charAt(i);
 }
 return(tempStr);
}

/******************************************************************************
*File name:checkNull(element,value)
*Description:Check if the value is NULL
*Input parameters:
* element - Name of the form element.
* value- The value of the element.
*Return:true on success ,false on error
******************************************************************************/
function checkNull(element,value){
 if(value==''){
  alert(element+" should not be left blank!");
  return false;
 }

 temp=trim(value);
 if(temp==''){
  alert(element+" should not be only spaces!")
  return false;
 }

 return true;
}


/******************************************************************************
*File name:checkContent(value,start,content)
*Description:Check the start character and the body of the string.
*Input parameters:
*   value - The value to be checked
* start - a string which contains the validate character for the first
*  character and "@NULL" on no check on the first character .
* content-  a string which contains the validate character for the remain
*  part of the String.
*Return:true on success ,false on error
******************************************************************************/
function checkContent(value,start,content){ 
    ch1 =value.charAt(0);
    startnull="@NULL";
 if(start!=startnull){
  for(k = 0;k < start.length; k ++){
   if(ch1 == start.charAt(k)){
   break;
   }
  }
  if(k == start.length){
   return false;
  }
    }
 
    for(i = 0;i < value.length;i ++ ){
  ch = value.charAt(i);
  for(j = 0;j < content.length;j ++ ){
   if( ch == content.charAt(j)){
    return true;
   }
  }
  if(j==content.length){
   return false;    
  }
 }
 
 return(true);
}

/******************************************************************************
*File name:checkGeneralInput(element,value)
*Description:Check the general input:should only be space and character and not
* null.
*Input parameters:
* element - Name of the form element.
* value- The value of the element.
*Return:true on success ,false on error
******************************************************************************/
function checkGeneralInput(element,value){
 isOk=checkNull(element,value);
 if(!isOk){  
  return false;
 }
 
 str=" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 content=checkContent(value,"@NULL",str);
 
 if(content==true){ 
  return true;
 }
 else{
  alert(element+" should only be space and character!" );
  return false;
 }

}

/******************************************************************************
*File name:checkAddr(element,value)
*Description:Should not be left blank and only spaces(Max 50 characters)
*Input parameters:
* element - Name of the form element.
* value- The value of the form.
*Return:flag-relay on the return value of checkNull(element,value)
******************************************************************************/
function checkAddr(element,value){
 result=checkNull(element,value);
 return result;
}

/******************************************************************************
*File name:checkGender(value)
*Description:should select at least one option
*Input parameters:* 
* value- The value of the element.
*Return:true on success ,false on error
******************************************************************************/
function checkGender(value){
 for(i=0;i<value.length;i++){
  if(value[i].checked==true){
  return true;
  }
 }
 alert("Please select your gender")
 return false;
}

/******************************************************************************
*File name:checkName(element,value)
*Description:should meet checkGeneralInput(element,value);
*Input parameters:
* element - Name of the form element.
* value- The value of the element.
*Return:flag-relay on the value of checkGeneralInput(element,value)
******************************************************************************/

function checkName(element,value){
 flag=checkGeneralInput(element,value);
 return flag;
}

/******************************************************************************
*File name:checkCity(element,value)
*Description:should meet checkGeneralInput(element,value);
*Input parameters:
* element - Name of the form element.
* value- The value of the element.
*Return:flag-relay on the value of checkGeneralInput(element,value)
******************************************************************************/
function checkCity(element,value){
 flag=checkGeneralInput(element,value);
 return flag;
}

/******************************************************************************
*File name:checkState(element,value)
*Description:should meet checkGeneralInput(element,value);
*Input parameters:
* element - Name of the form element.
* value- The value of the element.
*Return:flag-relay on the value of checkGeneralInput(element,value)
******************************************************************************/
function checkState(element,value){
 flag=checkGeneralInput(element,value);
 return flag;
}

/******************************************************************************
*File name:checkPin(element,value)
*Description:Should not be blank,only numbers and spaces,only spaces not
* allowed.
*Input parameters:
* element - Name of the form element.
* value- The value of the element.
*Return:true on success ,false on error
******************************************************************************/
function checkPin(element,value){ 
 isOk=checkNull(element,value);
 if(!isOk)
  return false;
         str=" 1234567890";
 content=checkContent(value,"@NULL",str);
 if(content==true)
  return true;
 else{
  alert(element+" should be space and number");
  return false;
 }
}

/******************************************************************************
*File name:checkTel(element,value)
*Description:only numbers and spaces allowed
*Input parameters:
* element - Name of the form element.
* value- The value of the element.
*Return:true on success ,false on error
******************************************************************************/
function checkTel(element,value){
 str=" 1234567890";
 content=checkContent(value,"@NULL",str);
 if(content==true)
  return true;
 else{
         alert(element+" should be space and number");
  return false;
 }
}

/******************************************************************************
*File name:checkFax(element,value)
*Description:only numbers and spaces allowed
*Input parameters:
* element - Name of the form element.
* value- The value of the element.
*Return:true on success ,false on error
******************************************************************************/
function checkFax(element,value){
 str=" 1234567890";
 content=checkContent(value,"@NULL",str);
 if(content==true)
  return true;
 else
  return false;
}


/******************************************************************************
*File name:checkMail(element,value)
*Description:Only spaces not allowed,should have one '@' character and one or
* more '.','@' and '.' should come only after the first 5 characters.
*Input parameters:
* element - Name of the form element.
* value- The value of the element.
*Return:true on success ,false on error
******************************************************************************/
function checkEmail(element,value){
 isOk=checkNull(element,value);
 if(!isOk){
  return false;
 }
  
 index=value.indexOf(".");
 indexlast=value.lastIndexOf(".");
 if(index==-1||indexlast==value.length-1){
         alert("Email format invalid,should contain /"./"");
 return false;
 }

 place1=value.indexOf("@");
 place2=value.lastIndexOf("@");
 if(place1!=place2||place1==-1||place1<5){
    alert("Email format invalid,should contain /"@/" following 5 characters");
 return false;
 }

 return true;

}

/******************************************************************************
*File name:checkDate(element,value)
*Description:DD-MON-YYYY format,Should be a valid Date
*Input parameters:
* element - Name of the form element.
* date- date.
*Return:true on success ,false on error
******************************************************************************/

function checkDate(element,date){
       /*validate the content*/
        str="-1234567890ABCDEFGJLMNOPRSTUVYabcdefgjlmnoprstuvy";
 contentOK=checkContent(date,"@NULL",str);
 
 if(!contentOK){  
        alert(element+" contains invalid character! ")
  return false;
 } 
 
 
 /*validate the format*/
 index1=date.indexOf("-");
 index2=date.lastIndexOf("-");
 
 if(index1!=2||index2!=6||date.charAt(2)!="-"||date.charAt(6)!="-"){
  alert(element+" should be /"dd-mmm-yyyy/"");
  return false;
 }
 
 
 /*validate the input of day*/
 var day=date.substring(0,date.indexOf('-'));
 fDay=parseFloat(day); 
 
 
 if(isNaN(fDay)||(!isFinite(fDay))){
  alert("Day should be number please!")
  return false;
                   } 
 if(fDay>31||fDay<1){
         alert("Day"+" should be proper");
  return false;
 } 
 
 /*validate the input of month*/ 
 var month=
 date.substring(date.indexOf('-')+
 1,date.lastIndexOf('-')).toLowerCase();
 
 var arr = new Array('Jan',
 'Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
 
 for(var index = 0;index <= 11;index++){
  if(arr[index].toLowerCase()==month.toLowerCase())
   break;  
 }
 if(index>11){
  alert("Month"+" should be proper like /"Apr/apr /"");
  return false;
 } 
 
 
 /*validate the input of year*/
 var year=date.substring(date.lastIndexOf('-')+1,date.length);
 fYear=parseFloat(year);
 datenow=new Date();
 
 if(isNaN(fYear)||(!isFinite(fYear))){
   alert("Year should be number please!")
   return false;
                  }
 if(fYear>=datenow.getFullYear()){
   alert("Year should be proper");
   return false;
 }   
 
 
 /*validate the relation of month,day*/
 if(fDay>29&&"feb"==month.toLowerCase()){
  alert("Feb has only max 29 days and 28 when leap year");
         return false;   
 }
 if(fDay>28&&"feb"==month.toLowerCase()&&checkLeapYear(fYear)){  
  alert("Feb has only 28 days when leap year");
  return false; 
 }
  
 switch(month.toLowerCase()){
  case "apr":;
  case "june":;
  case "sep":;
  case "nov":if(fDay>30) {
  alert("Please check the relation between day and month!");
  return false;
  }
  default:break;
 }  
 return true;
}


/******************************************************************************
*File name:checkID(element,value)
*Description:Should not be blank,Only numbers
*Input parameters:
* element - Name of the form element.
* value- The value of the element.
*Return:true on success ,false on error
******************************************************************************/
function checkID(element,value){
 isOk=checkNum(element,value);
 if(!isOk){
      return false;
  }
        else
 return true;
}

/******************************************************************************
*File name:checkDeposit(element,value)
*Description:Only numbers .Amount should be greater than 500
*  (Maximum of two decimal points are allowed)
*Input parameters:
* element - Name of the form element.
* value- The value of the element.
*Return:true on success ,false on error
******************************************************************************/
function checkIniDeposit(element,value){
    isOk=checkNum(element,value);
 if(!isOk){
         return false;
 }
 
 temp=parseFloat(value);
 if(temp<=500){
  alert("Initial deposit should larger than 500Rs")
  return false;
 } 
 return true;
}

/******************************************************************************
*File name:checkAccNum(element,value)
*Description:Should not be blank,only numbers
*Input parameters:
* element - Name of the form element.
* value- The value of the element.
*Return:true on success ,false on error
******************************************************************************/
function checkAccNum(element,value){
        isOk=checkNum(element,value);
        if(!isOk){
        return false;
        }
 else
 return true;
}

/******************************************************************************
*File name:checkAmount(element,value)
*Description:Amount should be greater than 0 (Maximum two decimal
* points are allowed),only numbers
*Input parameters:
* element - Name of the form element.
* value- The value of the element.
*Return:true on success ,false on error
******************************************************************************/
function checkAmount(element,value){
 isOK=checkNull(element,value);
 if (!isOK)
 return false;
 
 str=".1234567890";
 content=checkContent(value,"@NULL",str);
 if(content!=true){
               alert(element+" should be number and /"./" only!");
               return false;
 }
 
 index=value.indexOf(".");
 index2=value.lastIndexOf(".");
 
 if(index!=index2){
  alert(element+" format error!");
  return false;
 }
 else if(index!=-1&&index!=value.length-3){
  alert("Two decimal points are allowed");
  return false;
 }
 
 temp=parseFloat(value); 
 if(temp<0){
  alert(element+" should be greater than 0 ");
 return false;
 }  
 return true;
}

JavaScript Validation Framework教程 例子加说明,让你轻松掌握JavaScript Validation Framework框架的使用。就这么简单。 立即下载

相关推荐

jsvalidation 强大而灵活的表单客户端验证框架

JSValidation是强大灵活的客户端验证框架。在应用服务器或者开发框架不提供验证的情况下,例如,普通的JSP, ASP, PHP等开发,以及一些不提供验证支持的开发框架,如Tapestry, Velocity等,JSValidation提供了一种灵活的解决方案。与其他验证方式相比,它最大的优点在于独立与易于集成。纯JavaScript结构,可以很容易的集成到现有的应用中而不论现有的应用是基于什么语言。将所有的表单验证集中管理,使得维护应用更加容易。简便的XML配置,易于扩充的验证方式(目前支持13种验证,囊括了大部分常用表单验证),使得JSValidation成为验证框架的首选。 <br>1. JSValidation是什么?<br>如首页所说,JSValidation是客户端表单验证框架,用在BS系统中,或者简单的网页系统中。表单验证在这些开发中很常见:新用户注册,需要校验某些字段;用户登陆,需要校验;等等。在这之前,页面开发者(JavaScript开发者)需要编写大量的JavaScript来与表单对象交互,并进行校验。常见的校验如不能为空,必须满足长度要求,必须为数字,必须为Email等等。根据一般的经验,如果表单中需

JavaScript Validation Framework 运行时错误。

JavaScript Validation Framework 运行时错误: TypeError:对象不支持“load”属性或方法,任何运行错误都会导致该域验证失败。 将浏览器设置成兼容bai模式即可。 设置方法: 打开IE浏览器du。 点击键盘上的Alt按键zhi,呼出隐藏的设置选项。 点击“dao工具”进入浏览器工具。 在工具列表中有一项“兼容性视图设置”点击进入。 我们在兼容性视图中显示Internet站点(I)和使用microsoft兼容性列表(U)前面的方框打上勾。 点击保存退出就算是将兼容性视图

Zola的博客 2785

解决ArcGIS-OpenStreetMap Toolbox-Load OSM File错误

在安装成功OpenStreetMap Toolbox后,首次运行Load OSM File工具,出现以下错误

Zjf的博客 8820

限定IE浏览器的网址验证域失败解决方案

传统报名、考试系统经常会碰到的一个问题: JavaScript Validation Framework 运行时错误: TypeError:对象不支持“load”属性或方法 任何运行错误都会导致该域验证失败 我是在国家卫生健康委报名的时候碰到的这个问题。 解决方案: 1.打开IE浏览器。 2.点击键盘上的Alt按键,呼出隐藏的设置选项。 3.点击“工具”进入浏览器工具。 4.在工具列表中有一项“兼容性视图设置”点击进入。 5.添加该网页即可解决 ...

lzzry1314的博客 2182

Matt Pocock Skills — AI 编码代理技能包介绍与使用指南

《Matt Pocock Skills:AI编码代理技能包指南》 摘要: Matt Pocock Skills是一套开源AI编码代理技能包,旨在解决AI辅助开发中的四大痛点:需求理解偏差、token浪费、代码质量差和架构腐化。该技能包包含多种实用工具:/grill-with-docs用于需求对齐,/tdd实现测试驱动开发,/diagnose提供规范化调试流程,/triage管理issue生命周期。核心思想包括:通过拷问式对齐确保需求理解一致,建立共享领域语言提高沟通效率,快速反馈闭环加速开发,以及持续架构维

qq_45859163的博客 2221

pycharm添加Anaconda解释器显示不出来

因为我之前下载的是pycharm最新版本2024.1的,所以我抱着试一试的心态卸载重装了2021.3.3的,创建新文件的时候立刻就自己识别好了conda环境。就是图中画圈的地方,之前一直显示为python的图标,但是再Python Interpreter后面跟的路径确实是我下载anaconda的地方。另外一种方法就是使用Virtualenv Environment方式配置,但是我的pycharm还是没有识别出conda的图标。首先是这位的方法,先添加系统解释器,再重启,但是我的图标还是python。

2202_75803271的博客 4006

JavaScript 表单验证框架 - form-validation.js 推荐内容

JavaScript 表单验证框架 - form-validation.js 推荐内容 1. 项目基础介绍及主要编程语言 form-validation.js 是一个由社区驱动的开源项目,旨在提供一个高度可定制的 JavaScript 表单验证框架。该项目使用 TypeScript 作为主要编程语言,同时使用了 JavaScript、HTML 等相关技术。它遵循 MIT 许可证,允许用户自由使用、...

gitblog_01135的博客 452

PaddleOCR实战:给图片‘加个框’,轻松搞定小图和长图文字识别不准的难题

本文探讨了PaddleOCR在处理小图和长图时识别精度下降的问题,并提出通过图像边框预处理技术显著提升OCR识别效果。详细介绍了使用OpenCV实现智能边框添加的方法,包括核心原理、工程实践中的关键细节以及性能优化策略,帮助开发者轻松解决非常规尺寸图像的文本检测难题。

weixin_29313547的博客 188

探索form-validation.js:一款强大的表单验证库

探索form-validation.js:一款强大的表单验证库 在现代Web开发中,表单验证是不可或缺的一部分。无论是用户注册、登录还是数据提交,一个高效且易于使用的表单验证库可以极大地提升开发效率和用户体验。今天,我们将介绍一款名为form-validation.js的开源项目,它以其强大的功能和简洁的API设计,成为了开发者们的首选。 项目介绍 form-validation.js是一款基于J...

gitblog_01155的博客 499

手把手教你用若依WMS搭建企业级仓库管理系统(Vue+Spring Boot实战)

本文提供了一份基于若依框架(RuoYi)快速搭建企业级仓库管理系统(WMS)的实战指南。详细介绍了从环境准备、项目初始化到核心功能模块(如入库流程、库存管理看板)深度定制的全过程,并涵盖Lodop打印集成、移动端PWA适配及生产环境Docker部署等高级主题,帮助开发者高效构建稳定可用的WMS系统。

weixin_29015899的博客 564

PCL点云DBSCAN聚类算法:基于密度的点云聚类

核心点是在给定半径内拥有足够多邻居点的点,边界点是在给定半径内没有足够多邻居点但是位于核心点的邻域内的点,噪声点是既不是核心点也不是边界点的点。本文将介绍PCL中的DBSCAN(基于密度的空间聚类应用噪声)算法,用于点云数据的聚类。上述示例代码首先从PCD文件中读取点云数据,并设置了DBSCAN聚类的参数,包括邻域搜索半径(epsilon)和邻域内最小点数(min_points)。需要注意的是,示例代码中的点云数据格式为pcl::PointXYZ,如果使用其他类型的点云数据,需要相应地修改代码。

LpmShell的博客 1239

JS表单校验插件Validation

1、首先先去validation官网下载:https://jqueryvalidation.org/ 2、进入到官网主页后,下拉找到download,点击 3、点击download后,跳转到GitHub界面,下拉找到jquery-validation-1.19.1.zip,点击就开始下载了。 4、下载完后你就会得到下面的这样的一个文件夹: 5、我们需要用的是两个文件: 第一个...

仙女的博客 1827

大模型在电力交易功率预测中的应用:短期,超短期,中长期的完整解决方案代码详解

本文介绍了基于大模型的电力交易功率预测系统,该系统覆盖超短期(15分钟-1小时)、短期(1-6小时)和中长期(1天-1月)三个时间尺度。文章详细阐述了数据准备与特征工程,包括多源数据集成和特征重要性分析。在模型构建方面,采用了Temporal Fusion Transformer (TFT)模型进行超短期预测,Informer模型进行短期预测,以及N-HiTS模型进行中长期预测。此外,文章还探讨了概率预测与风险分析,并介绍了模型部署与交易策略集成的实现。最后,文章总结了系统的贡献,并展望了未来发展方向,如市

专注AI大模型,软件混淆,授权 1264

jQuery.validation.js实现前台表单验证

待编辑

苏丶小魂的专栏 486

RK3588平台开发系列讲解(DMA篇)DMA engine使用

Linux 内核的 DMA 引擎提供了一组完整的接口,用于申请和释放 DMA 通道、准备 DMA 描述符、启动和控制 DMA 传输,以及同步和管理缓存。通过这些接口,内核能够高效地处理异步的 DMA 传输任务,减少 CPU 的干预,提高数据传输的效率。

内核笔记 1834

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

form-backend-validation与Vue.js结合:打造现代表单体验

form-backend-validation是一款轻量级表单验证库,它能帮助开发者轻松实现基于后端逻辑的表单验证功能。通过与Vue.js框架的无缝集成,你可以快速构建出既美观又实用的现代Web表单,为用户提供流畅的交互体验。 ## 为什么选择form-backend-validation? 在前端开发中,表单验证是一个常见但却容易出错的环节。传统的前端验证方式往往需要编写大量重复代码,而且难

gitblog_00115的博客 1076

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

jquery.validation.js 表单验证

官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuery plugin: Validation 使用说明   一导入js库   二、默认校验规则 (1)required:true                必输字段 (2)remote:"check.php"      

不忘初心,方得始终 7659

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

jQuery插件Validation验证表单实现javascript表单智能验证功能

介绍一个表单验证的jQuery插件Validation,Validation与Validate名字基本上都差不多,这两个插件的区别在于,Validate插件只能提供简单的几种验证,而Validation插件却能自定义表单长度,类型,自定义错误提示,自动设置焦点等等,应该说是jQuery表单验证界最强有力的品牌,使用网站最多,应用最广泛的一个jQuery验证表单插件,这里主要是介...

dicongtuo4349的博客 160

bootstrap3-validation.js bootstrap 的jquery 表单验证

转载:https://github.com/mrlong/bootstrap3-validation.js bootstrap3-validation.js

Zoe_Wang_ing的专栏 1万+

23 JavaScript 插件-----使用jQuery Validation实现表单验证

首先,下载jquery validation插件,放入你的项目中webapp/static/assets/plugins/... 1.页面引入 <!-- jQuery Validation 1.14.0 --> <script src="/static/assets/plugins/jquery-validation/js/jquery.validate.js">&l...

shmily的博客 242
上一篇: 需求分析的20条法则
下一篇: 产品开发模式管理网站开发
Three_H
博客等级 码龄22年 1粉丝 50原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值