获取 7天前 , 昨天 , 一个月前的函数表达式:
GetDateStr(AddDayCount) {
var dd = new Date();
dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
var y = dd.getFullYear();
var m = (dd.getMonth()+1)<10?"0"+(dd.getMonth()+1):(dd.getMonth()+1);//获取当前月份的日期,不足10补0
var d = dd.getDate()<10?"0"+dd.getDate():dd.getDate();//获取当前几号,不足10补0
return y+"-"+m+"-"+d;
}
调用 : GetDateStr(-30)
获取当前字符串的字符长度,中文两个字符,英文和数字一个字符 :
DataLength(fData){
var intLength = 0
for (var i = 0; i < fData.length; i++) {
if ((fData.charCodeAt(i) < 0) || (fData.charCodeAt(i) > 255))
intLength = intLength + 2
else
intLength = intLength + 1
}
return intLength
}
调用 : DataLength('这里写字符串')
Vue常见的金额交互函数 :
watch: {
'JeValue':function(){ //监听金额输入
this.JeValue = this.JeValue.replace(/[^\d\.]/g, '');
//必须保证第一个为数字而不是.
this.JeValue =this.JeValue.replace(/^\./g,'');
//保证只有出现一个.而没有多个.
this.JeValue = this.JeValue.replace(/\.{2,}/g,'.');
//保证.只出现一次,而不能出现两次以上
this.JeValue = this.JeValue.replace('.','$#$').replace(/\./g,'').replace('$#$','.');
//只能输入两位小数
this.JeValue =this.JeValue.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');
}
}
常用的正则表达式 :
手机号 : var test = /^1[3456789]\d{9}$/
正整数 : var text = /^[+]{0,1}(\d+)$/g //(包括零)
正整数 : var tetx = /^[1-9]\d*$/g //(不包括零)
金额 :var tetx = /((^[1-9]\d*)|^0)(\.\d{0,2}){0,1}$/ (0.01)
1-9小数点后一位 : var Begu = /^([1-9](\.\d)?|10)$/
排除特殊符号 : let test = /[^\a-\z\A-\Z0-9\u4E00-\u9FA5\.\,\?\<\>\。\(\)\(\)\,\-\——\=\;\@\!\!\+\$]/g
英文,汉字,数字 :let test = /[^\a-\z\A-\Z0-9\u4E00-\u9FA5]/g
英文,汉字:let test = /[^\a-\z\A-\Z\u4E00-\u9FA5]/g
邮箱:let test = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/
16到19位数银行卡号: let test = /^([1-9]{1})(\d{15}|\d{18})$/
身份证:let test = /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/