标签:ali ring color style date tchar function element return
/** * 验证月份表单输入是否合法 * pattern : 月份格式字符串 * id : 表单id */ function validateMonth(pattern, id) { var text = document.getElementById(id); var monthStr = text.value; var splitChar = ""; if(pattern.length > 6) splitChar = pattern.substring(4, pattern.length - 2); eval("var re = /\\d{4}" + splitChar + "\\d{2}$/;"); //var re = /\d{4}-\d{2}$/; if(monthStr.match(re) == null) { alert("请参考格式[" + pattern + "]输入!\n" + "e.g \"2010" + splitChar + "11\" or \"2010" + splitChar + "03\""); text.value = ""; text.focus(); return false; } return true; }
需要动态拼出脚本字符串传给eval()方法执行时,需要对字符‘\‘转义
标签:ali ring color style date tchar function element return
原文地址:https://www.cnblogs.com/hu-kang/p/12082338.html