各种正则判断(前端)

匹配表情:

/[^\u0020-\u007E\u00A0-\u00BE\u2E80-\uA4CF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF\u0080-\u009F\u2000-\u201f\u2026\u2022\u20ac\r\n]/g;

匹配只能输入中文或英文或者数字: /^[\u4e00-\u9fa50-9A-Za-z]+$/

匹配手机号码:/^[1][3,4,5,7,8][0-9]{9}$/

匹配整数:/^\d+$/

匹配整数或小数点后一位 两位:/^\d+\.{0,1}\d{0,2}$/

匹配微信号:/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/

小数点后两位自动补全:

function overFormat(value) {

let v = value;
if ( v === '') {
v = '0.00';
} else if ( value === '0') {
v = '0.00';
} else if (v === '0.') {
v = '0.00';
} else if (/^0 +\d +\.?\d *.*$ /.test(v)) {
v = v.replace(/^0+(\d+\.?\d*).*$/, '$1');
v = inp.getRightPriceFormat(v).val;
} else if (/^0\.\d$/.test(v)) {
v = v + '0';
} else if (!/^\d+\.\d{2}$/.test(v)) {
if (/^\d+\.\d{2}.+/.test(v)) {
v = v.replace(/^(\d+\.\d{2}).*$/, '$1');
} else if (/^\d+$/.test(v)) {
v = v + '.00';
} else if (/^\d+\.$/.test(v)) {
v = v + '00';
} else if (/^\d+\.\d$/.test(v)) {
v = v + '0';
} else if (/^[^\d]+\d+\.?\d*$/.test(v)) {
v = v.replace(/^[^\d]+(\d+\.?\d*)$/, '$1');
} else if (/\d+/.test(v)) {
v = v.replace(/^[^\d]*(\d+\.?\d*).*$/, '$1');
ty = false;
} else if (/^0+\d+\.?\d*$/.test(v)) {
v = v.replace(/^0+(\d+\.?\d*)$/, '$1');
ty = false;
} else {
v = '0.00';
}
}
return v;
}


你可能感兴趣的:(javascript技术基础,h5技术基础)