<input type="text" name="color"> <input type="button" value="check" οnclick="checkColor('color')"> 检查一下颜色值 ,正确是#+六位十六进制数 比如:#3EEF4A <script language="JavaScript"> function checkColor(object) { var pattern = /^#[0-9a-fA-F]{6}$/ var obj = eval("document.all['" + object + "'].value") ; if(obj.match(pattern)==null) alert("错误") ; else alert("正确") ; } </script>