<SCRIPT LANGUAGE="javascript" type="text/javascript">
function frmValid(obj)
{
// Elements array, initialization for validation
elems = new Array(
new Array(
'username', // name of elements to be validated
'value.length<1 || value.search(/[^a-zA-z0-9_]/)>=0',
// validation condition
'无效的用户名:只能输入6-20位字母、数字、下划线的组合!'),
// prompt on failure
new Array(
'password',
'value.length<5 || value.search(/[^a-zA-z0-9_]/)>=0',
'无效的密码:只能输入6-20位字母、数字、下划线的组合!'),
new Array(
'email',
'isMail(value)==false',
'Email是您在网上的重要联络工具,请务必正确填写!')
);
// Validate here, using eval statement.
for(i = 0; i < elems.length; i++)
{
with(eval('obj.'+elems[i][0]))
{
if(eval(elems[i][1]))
{
window.alert(elems[i][2]);
focus();
return false;
}
}
}
return true;
}
//-->
</SCRIPT>
2、为form添加onsubmit属性:
<form ... onsubmit='return frmValid(this)'>