请高手帮我改一下这个formcheck.js文件,感谢!

rene126 2007-08-13 04:37:24
我新手都不算,完全不懂,就像去掉分类信息发布页面的EMAIL和TAG的检测,使用户不用填写也能发信息,l谢谢了。
var ValidFone = false;
var CheckQQ = false;
function gid(x) { return document.getElementById(x); }
function clearMe(x) { document.getElementById('info_'+x+'_hint').innerHTML = '';}
function IsNumeric(sText) {
var ValidChars = "0123456789-";
var IsNumber=true;
var Char;


for (i = 0; i < sText.length && IsNumber == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsNumber = false;
}
}
return IsNumber;
}
function isEmail(email) {
invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;";

// Check for null
if (email == "") {
return true;
}

// Check for invalid characters as defined above
for (i=0; i<invalidChars.length; i++) {
badChar = invalidChars.charAt(i);
if (email.indexOf(badChar,0) > -1) {
return false;
}
}
lengthOfEmail = email.length;
if ((email.charAt(lengthOfEmail - 1) == ".") || (email.charAt(lengthOfEmail - 2) == ".")) {
return false;
}
Pos = email.indexOf("@",1);
if (email.charAt(Pos + 1) == ".") {
return false;
}
while ((Pos < lengthOfEmail) && ( Pos != -1)) {
Pos = email.indexOf(".",Pos);
if (email.charAt(Pos + 1) == ".") {
return false;
}
if (Pos != -1) {
Pos++;
}
}

// There must be at least one @ symbol
atPos = email.indexOf("@",1);
if (atPos == -1) {
return false;
}

// But only ONE @ symbol
if (email.indexOf("@",atPos+1) != -1) {
return false;
}

// Also check for at least one period after the @ symbol
periodPos = email.indexOf(".",atPos);
if (periodPos == -1) {
return false;
}
if (periodPos+3 > email.length) {
return false;
}
return true;
}
function itxt(el,s) {
document.getElementById(el+'_hint').innerHTML = s;
/*
if (!el)
return;
var tmpid = el + '_hint';
else {
document.getElementById(tmpid).innerHTML = s;
}*/
}
function emp(id) {
if (document.getElementById(id).value == '')
return true;
/* - removed
else
return document.getElementById(id).value;
*/
}
function postcheck2() {
if (emp('info_title'))
itxt('info_title', '请输入标题');
if (emp('info_contact'))
itxt('info_contact', '请输入联系方式!');
if (ValidFone == true) {
if (IsNumeric(gid('info_contact').value)) {
itxt('info_contact','不是有效的电话号码!');
}
}
if (CheckQQ == true) {
if (isNumeric(gid('info_qq').value)) {
itxt('info_qq','无效QQ号码');

}
}
if (emp('info_mail'))
itxt('info_mail','请输入电子邮件地址!');
if (!emp('info_mail') && !isEmail(gid('info_mail').value))
itxt('info_mail','无效的email地址!');
if (emp('info_man'))
itxt('info_man','发布者不能为空!');
if (emp('tag1') && emp('tag2') && emp('tag3'))
itxt('info_tag','请输入至少一个TAG!');
}
function postcheck() {
/*
if (Debug = true ) {
alert(document.getElementById('info_content').value);
}
*/
if (emp('info_title')) {
itxt('info_title','请输入标题!');
return false;
}
else if (emp('info_contact')) {
itxt('info_contact','请输入联系方式!');
return false;
}
else if (emp('info_mail')) {
itxt('info_mail','请输入您的邮箱地址!');
return false;
}
else if (!isEmail(gid('info_mail').value)) {
itxt('info_mail','无效的email地址!');
return false;
}
else if (emp('info_man')) {
itxt('info_man','发布者不能为空!');
return false;
}
else if (emp('tag1') && emp('tag2') && emp('tag3')) {
itxt('info_tag','请输入至少一个TAG!');
return false;
}
/*
else if (emp('info_content')) {
itxt('info_content','请输入信息内容!');
return false;
}
*/
else {
/*
** quick fix 07/04/2006 - kast one
*/
//dc=document.frames['info_content___Frame'].document.frames[0].document.getElementsByTagName('body')[0].innerHTML;
// document.infopost.info_content.value=dc;
/* eof quickfix */
//alert(document.infopost.info_content.value);
//ajaxFormSubmit(document.infopost,document.getElementById('postArea'));
return true;

}
}

...全文
225 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
rene126 2007-08-13
  • 打赏
  • 举报
回复
谢谢!修改好了,但是发布页面显示有错误,估计mod_post.asp还需要改一下,我改了很久都不行。继续加分。。。
<%response.charset="utf-8"
dim postbuf
set rsuser_pub=server.createobject("ADODB.Recordset")
sqluser_pub="select * from config where id=1"
rsuser_pub.open sqluser_pub,conn,1,1
if not rsuser_pub.eof then
user_pub=rsuser_pub("user_pub")
end if
rsuser_pub.close
set rsuser_pub=nothing

if user_pub=1 then
if session("user_ses")="" then
postbuf = postbuf + "<h3 style=""width: 500px;border-bottom: 2px solid #369;display: block;margin-bottom: 20px;"">您未注册或未登录,不能发布信息!</h3>"
%>
<!--#include file="mod_reg.asp"-->
<%response.charset="utf-8"
postbuf = postbuf + regbuf
else
call pubinfo()
end if
else
call pubinfo()
end if
sub pubinfo()
postbuf = postbuf + "<script type=""text/javascript"" src=""/scripts/ajax_func.js""></script>"&vbcrlf
postbuf = postbuf + "<script type=""text/javascript"" src=""/scripts/formcheck.js""></script>"&vbcrlf
postbuf = postbuf + "<div id=""postArea""><form name=""infopost"" method=""post"" action=""postsave.asp"" id=""infopost"" onsubmit=""javascript:return postcheck();"">"
postbuf = postbuf + "<div class=""row"">"
postbuf = postbuf + "<div class=""label"">标题:</div>"
postbuf = postbuf + "<div class=""formw""><input onblur=""postcheck2()"" onfocus=""clearMe('title');"" name=""info_title"" type=""text"" class=""textfield"" id=""info_title"" size=""40"" maxlength=""50""><i class=""hint"" id=""info_title_hint"">*</i></div>"
postbuf = postbuf + "</div>"
set rsg=server.createobject("ADODB.Recordset")
sqlg="select * from users where user_name='"&session("user_ses")&"'"
rsg.open sqlg,conn,1,1
if not rsg.eof then
defautinfo_man=rsg("user_realname")
defautinfo_conn=rsg("user_contact")
defautinfo_mail=rsg("user_email")
end if
postbuf = postbuf + "<script type=""text/javascript"" src=""scripts/post.asp""></script><div class=""row"">"
postbuf = postbuf + "<div class=""label"">联系电话:</div>"
postbuf = postbuf + "<div class=""formw""><input onblur=""postcheck2()"" onfocus=""clearMe('contact');"" name=""info_contact"" type=""text"" class=""textfield"" id=""info_contact"" size=""25"" maxlength=""50""><i class=""hint"" id=""info_contact_hint"">*</i></div>"
postbuf = postbuf + "</div>"
postbuf = postbuf + "<div class=""row""><div class=""label"">QQ:</div>"
postbuf = postbuf + "<div class=""formw""><input name=""info_qq"" type=""text"" class=""textfield"" id=""info_qq"" size=""25"" maxlength=""20""></div>"
postbuf = postbuf + "</div>"
postbuf = postbuf + "<div class=""row""><div class=""label"">MSN:</div>"
postbuf = postbuf + "<div class=""formw""><input name=""info_msn"" type=""text"" class=""textfield"" id=""info_msn"" size=""25"" maxlength=""50""></div>"
postbuf = postbuf + "</div>"

postbuf = postbuf + "<div class=""row"">"
postbuf = postbuf + "<div class=""label"">电子邮件:</div>"
postbuf = postbuf + "<div class=""formw""><input onblur=""postcheck2()"" onfocus=""clearMe('mail')"" name=""info_mail"" type=""text"" class=""textfield"" id=""info_mail"" value="""&defautinfo_mail&""" size=""25"" maxlength=""50""><i class=""hint"" id=""info_mail_hint"">*</i></div>"
postbuf = postbuf + "</div>"
postbuf = postbuf + "<div class=""row"">"
postbuf = postbuf + "<div class=""label"">联系人:</div>"
postbuf = postbuf + "<div class=""formw""><input onblur=""postcheck2()"" onfocus=""clearMe('man')"" name=""info_man"" type=""text"" class=""textfield"" id=""info_man"" value="""&defautinfo_man&""" size=""15"" maxlength=""50""><i class=""hint"" id=""info_man_hint"">*</i></div>"
postbuf = postbuf + "</div>"
postbuf = postbuf + "<div class=""row"">"
postbuf = postbuf + "<div class=""label"">TAGS:</div>"
postbuf = postbuf + "<div class=""formw""><input onblur=""postcheck2()"" onfocus=""clearMe('tag')"" class=""tag"" id=""tag1"" type=""text"" name=""tag1"" maxlength=""50"" xsize=""10""/>"
postbuf = postbuf + "<input onfocus=""clearMe('tag')"" class=""tag"" type=""text"" id=""tag2"" name=""tag2"" maxlength=""50"" xsize=""10""/>"
postbuf = postbuf + "<input onfocus=""clearMe('tag')"" class=""tag"" type=""text"" id=""tag3"" name=""tag3"" maxlength=""50"" xsize=""10""/><i class=""hint"" id=""info_tag_hint"">*</i></div>"
postbuf = postbuf + "</div>"
postbuf = postbuf + "<div class=""row"">"
postbuf = postbuf + "<div class=""label"">信息内容:</div>"
postbuf = postbuf + "<div class=""formw""><span style='color: red;'>请自觉不要发布与国家法律法规相抵触的内容。</span>"

Dim oFCKeditor
Set oFCKeditor = New FCKeditor
oFCKeditor.BasePath = "/FCKeditor/"

postbuf = postbuf + oFCKeditor.Create ("info_content")
postbuf = postbuf + "</div>"
postbuf = postbuf + "</div>"
postbuf = postbuf + "<div class=""row"" style=""margin-top: 6px;"">"
postbuf = postbuf + "<div class=""label"">类别:</div>"
postbuf = postbuf + "<div class=""formw"">"
postbuf = postbuf + "<select name=""s1"" size=""10"" id=""s1"" style=""width: 100px;""></select>"
postbuf = postbuf + "<select name=""s2"" size=""10"" id=""s2"" style=""width: 100px;""></select>"
postbuf = postbuf + "<select name=""s3"" size=""10"" id=""s3"" style=""width: 100px;""></select>"
postbuf = postbuf + "<select name=""s4"" size=""10"" id=""s4"" style=""width: 100px;""></select><script type=""text/javascript"">setup();</script></div>"
postbuf = postbuf + "</div>"
postbuf = postbuf + "<div class=""row"">"
postbuf = postbuf + "<div class=""label"">地区:</div>"
postbuf = postbuf + "<div class=""formw"">"

i=1

set rs_area=server.createobject("ADODB.Recordset")
sql_area="select * from area order by area_id desc"
rs_area.open sql_area,conn,1,1
while not rs_area.eof

tr=i mod 5
postbuf = postbuf + "<label class=""area""><input type=""radio"" name=""info_area"" value="""&rs_area("area_name")&""" id=""info_area"">"&rs_area("area_name")&"</label>"
if tr=0 then
postbuf = postbuf + "</tr><tr>"
end if
rs_area.movenext
i=i+1
wend
postbuf = postbuf +"</div>"
postbuf = postbuf +"</div>"
postbuf = postbuf +"<div class=""row"">"
postbuf = postbuf +"<div class=""label"">验证码:</div>"
postbuf = postbuf +"<div class=""formw"">"
postbuf = postbuf +"<input name=""yanzheng"" type=""text"" id=""yanzheng"" size=""5"" maxlength=""20""> <img name="""" src=""secucode.asp"" width=""40"" height=""11"" alt="""">"
postbuf = postbuf +"</div>"
postbuf = postbuf +"</div>"
postbuf = postbuf +"        <input type=""submit"" name=""Submit"" value="" 发 布 "" >"
postbuf = postbuf +"</form></div>"
rsg.close
set rsg=nothing
end sub

%>
sz_dongli 2007-08-13
  • 打赏
  • 举报
回复
var ValidFone = false;
var CheckQQ = false;
function gid(x) { return document.getElementById(x); }
function clearMe(x) { document.getElementById('info_'+x+'_hint').innerHTML = '';}
function IsNumeric(sText) {
var ValidChars = "0123456789-";
var IsNumber=true;
var Char;


for (i = 0; i < sText.length && IsNumber == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsNumber = false;
}
}
return IsNumber;
}
function isEmail(email) {
invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;";

// Check for null
if (email == "") {
return true;
}

// Check for invalid characters as defined above
for (i=0; i<invalidChars.length; i++) {
badChar = invalidChars.charAt(i);
if (email.indexOf(badChar,0) > -1) {
return false;
}
}
lengthOfEmail = email.length;
if ((email.charAt(lengthOfEmail - 1) == ".") || (email.charAt(lengthOfEmail - 2) == ".")) {
return false;
}
Pos = email.indexOf("@",1);
if (email.charAt(Pos + 1) == ".") {
return false;
}
while ((Pos < lengthOfEmail) && ( Pos != -1)) {
Pos = email.indexOf(".",Pos);
if (email.charAt(Pos + 1) == ".") {
return false;
}
if (Pos != -1) {
Pos++;
}
}

// There must be at least one @ symbol
atPos = email.indexOf("@",1);
if (atPos == -1) {
return false;
}

// But only ONE @ symbol
if (email.indexOf("@",atPos+1) != -1) {
return false;
}

// Also check for at least one period after the @ symbol
periodPos = email.indexOf(".",atPos);
if (periodPos == -1) {
return false;
}
if (periodPos+3 > email.length) {
return false;
}
return true;
}
function itxt(el,s) {
document.getElementById(el+'_hint').innerHTML = s;
/*
if (!el)
return;
var tmpid = el + '_hint';
else {
document.getElementById(tmpid).innerHTML = s;
}*/
}
function emp(id) {
if (document.getElementById(id).value == '')
return true;
/* - removed
else
return document.getElementById(id).value;
*/
}
function postcheck2() {
if (emp('info_title'))
itxt('info_title', '请输入标题');
if (emp('info_contact'))
itxt('info_contact', '请输入联系方式!');
if (ValidFone == true) {
if (IsNumeric(gid('info_contact').value)) {
itxt('info_contact','不是有效的电话号码!');
}
}
if (CheckQQ == true) {
if (isNumeric(gid('info_qq').value)) {
itxt('info_qq','无效QQ号码');

}
}

if (!emp('info_mail') && !isEmail(gid('info_mail').value))
itxt('info_mail','无效的email地址!');
if (emp('info_man'))
itxt('info_man','发布者不能为空!');

}
function postcheck() {
/*
if (Debug = true ) {
alert(document.getElementById('info_content').value);
}
*/
if (emp('info_title')) {
itxt('info_title','请输入标题!');
return false;
}
else if (emp('info_contact')) {
itxt('info_contact','请输入联系方式!');
return false;
}
else if (!isEmail(gid('info_mail').value)) {
itxt('info_mail','无效的email地址!');
return false;
}
else if (emp('info_man')) {
itxt('info_man','发布者不能为空!');
return false;
}
/*
else if (emp('info_content')) {
itxt('info_content','请输入信息内容!');
return false;
}
*/
else {
/*
** quick fix 07/04/2006 - kast one
*/
//dc=document.frames['info_content___Frame'].document.frames[0].document.getElementsByTagName('body')[0].innerHTML;
// document.infopost.info_content.value=dc;
/* eof quickfix */
//alert(document.infopost.info_content.value);
//ajaxFormSubmit(document.infopost,document.getElementById('postArea'));
return true;

}
}

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧