1. 判断不包含某一字符串
/^((?!abc).)*$/.test(‘abc‘) //判断是否包含abc
2. 格式化金钱
function formatMoney(s){ if(/[^0-9\.]/.test(s)) return "invalid value"; s=s.replace(/^(\d*)$/,"$1."); s=(s+"00").replace(/(\d*\.\d\d)\d*/,"$1"); s=s.replace(".",","); var re=/(\d)(\d{3},)/; while(re.test(s)) s=s.replace(re,"$1,$2"); s=s.replace(/,(\d\d)$/,".$1"); return "¥" + s.replace(/^\./,"0.") }
更简单的方法详见:js,正则实现金钱格式化
3. 校验手机号
function isTelCode(str) { var reg= /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/; return reg.test(str); }
4. 校验邮箱
function IsEmail(str) { var reg=/^([a-zA-Z0-9_-])[email protected]([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+$/; return reg.test(str); }
原文地址:https://www.cnblogs.com/Kuro-P/p/8971349.html
时间: 2024-09-30 02:59:37