javascript 日期验证正则 代码如下: var pattern = /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/ if (!pattern.test(document.form1.pro_date.value)) { alert("日期格式...
代码如下:/** * * 返回一个距离现在多长时间后的一个格式化的日期,如2009年9月5日 14:15:23 * 如:现在时间是2009年9月5日 14:15:23 timeLong=10秒 那么返回:2009年9月5日 14:15:33 * * @param int timeLong 一个 * @param String formatString YYYY-MM-DD hh:mm:ss * */ function getOneFormatDate(timeLong,formatString) { timeLong=parseInt(timeLong); timeLong=timeLong*1000; var myDate=new Date(); var futureDat...
代码如下: var lCSSCoder={ format : function(s){//格式化代码 s=s.replace(/\s*([\{\}\:\;\,])\s*/g,"$1"); s=s.replace(/\,[\s\.\#\d]*{/g,"{"); s=s.replace(/([^\s])\{([^\s])/g,"$1 {\n\t$2"); s=s.replace(/([^\s])\}([^\n]*)/g,"$1\n}\n$2"); s=s.replace(/([^\s]);([^\s\}])/g,"$1;\n\t$2"); s=s.replace(/;\s*;/g,";");//清除连续分号 return s; }, pack :function(s){//压缩代码 s=s.replace(/\/\*(.|\n)*?\*\//g,"");/...
为什么不用textarea呢? 1 没有高亮 2 tab键无法使用。——按tab键会切换到下个控件 3 没有代码格式化。——因为习惯了Eclipse的环境,可以使用ctrl+shift+F来代码进行格式化。 当然,我还没强大到自己实现的程度,而且用脚趾头都能想到肯定有人实现了,就看找不找得着。 经过了艰难的搜索,终于在SourceForge上找到一个叫EditArea的项目,感觉挺好。http://sourceforge.net/projects/editarea/ 它的sample也很清楚 在网页上用以下...
代码如下://-------------------------------------------- // 删除千分点。 //-------------------------------------------- function removeComma(number) { var num = number.replace(new RegExp(",","g"),""); if(/^[-+]?[0-9]+(\.[0-9]+)?$/.test(num)) { return num; } else { return number; } } //-------------------------------------------- //添加千分点。 //-------------------------------------------- function...
安装方法:用chrome浏览器访问 https://chrome.google.com/extensions/detail/pjkoglpbigbjijmncfkcpkcpddnelgbm?hl=zh-cn 【json格式化/压缩】工具 chrome下安装 :) 1、建一个新的文件夹 2、建一个名为 manifest.json的文件 3、打开这个 manifest.json文件,可以理解为配置文件 :) 包含以下内容 代码如下: { "name": "My First Extension",//扩展的名字 "version": "1.0", //版本 "description": "json format", //描述 "browser_...
我们在项目中经常遇到需要格式化的金额数和银行卡号,一般我们常见的有两种表现形式:输入框内格式化和输入框外格式化。这里我主要把我在项目中遇到的输入框内部格式化的,代码亮出来,框外的格式化相对简单一点。 页面代码:银行卡号格式化//卡号每4位一组格式化$("#bankCard").on("keyup", formatBC);function formatBC(e){$(this).attr("data-oral", $(this).val().replace(/\ +/g,""));//$("#bankCard").attr("data-oral")获取...
字符串转日期、日期转字符串// 2014-02-25 /** * 字符串转时间(yyyy-MM-dd HH:mm:ss) * result (分钟) */ stringToDate : function(fDate){ var fullDate = fDate.split("-"); return new Date(fullDate[0], fullDate[1]-1, fullDate[2], 0, 0, 0); } /** * 格式化日期 * @param date 日期 * @param format 格式化样式,例如yyyy-MM-dd HH:mm:ss E * @return 格式化后的金额 */ formatDate : function (date, format) { var...
代码如下: /* * Date Format 1.2.3 * (c) 2007-2009 Steven Levithan * MIT license * * Includes enhancements by Scott Trenda * and Kris Kowal * * Accepts a date, a mask, or a date and a mask. * Returns a formatted version of the given date. * The date defaults to the current date/time. * The mask defaults to dateFormat.masks.default. */ var dateFormat = function () { var token = /d{1,4}|m{1,4}|yy(?:yy...
代码如下:/** * 格式化数字 * Author : Z,Mingyu * 参数: * prmNum (Number) : 要格式化的数字 * prmPtn (String) : 格式化规则,例如:#,##0.00 * * prmNullValue : 当要格式化的数字为null、空或非数字时,返回的结果。默认为0 */ function formatNum(prmNum,prmPtn,prmNullValue){ var nullValue = prmNullValue ? prmNullValue : 0; if(prmNum == "" || prmNum == null) return nullValue; prmNum = prmNum.replace(/\,/g,"")...
昨天分享了 http://jscompress.sinaapp.com/ 这个小工具后,发现大家还是很喜爱的。因此今天我把它json化了.用json传输数据,也开放了api 本工具所有的功能实现都是由 http://jscompress.sinaapp.com/api 处理.(包括现在可以使用的这个在线压缩) 所有的数据交换均由 HTTP POST 输入处理后由 json 作为数据输出格式. API参数 : http://jscompress.sinaapp.com/api?get={type}&code=(code)&type={compress only}get={type},{type...
在jsp页面上可以使用在js中---------- Javascript也提供了对数字进行格式化输出的支持 Number对象提供的几种格式化函数: toExponential([fractionDigits]) :将数字按科学计数法格式返回,其中的fractionDigits值小数点后保留的位数。 toFixed([fractionDigits]) :将数字按指定的小数点位数返回,其中的fractionDigits值小数点后保留的位数。 toPrecision([precision]) :将数字按指定的精度返回(这个精度不是指小数点后几位),...
代码如下: (function ($) { var FormatDateTime = function FormatDateTime() { }; $.FormatDateTime = function (obj, IsMi) { var correcttime1 = eval(( new + obj.replace(new RegExp("\/", "gm"), "") + )); var myDate = correcttime1; var year = myDate.getFullYear(); var month = ("0" + (myDate.getMonth() + 1)).slice(-2); var day = ("0" + myDate.getDate()).slice(-2); var h = ("0" + myDate.getHours()).slice(...
十进制四舍五入 这两段代码帮助你做到四舍五入,对于你显示价格或者订单比较有用: 代码1: 代码如下: function CurrencyFormatted(amount) { var i = parseFloat(amount); if(isNaN(i)) { i = 0.00; } var minus = ; if(i < 0) { minus = -; } i = Math.abs(i); i = parseInt((i + .005) * 100); i = i / 100; s = new String(i); if(s.indexOf(.) < 0) { s += .00; } if(s.indexOf(.) == (s.length - 2)) { s += 0; } s = minus...
代码内容及下载地址 accounting.js代码如下: 代码如下: /*! * accounting.js v0.3.2 * Copyright 2011, Joss Crowcroft * * Freely distributable under the MIT license. * Portions of accounting.js are inspired or borrowed from underscore.js * * Full details and documentation: * http://josscrowcroft.github.com/accounting.js/ */ (function(root, undefined) { /* --- Setup --- */ // Create the local library o...