首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

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

2012-02-16 
请高手帮我改一下这个formcheck.js文件,感谢!我新手都不算,完全不懂,就像去掉分类信息发布页面的EMAIL和TA

请高手帮我改一下这个formcheck.js文件,感谢!
我新手都不算,完全不懂,就像去掉分类信息发布页面的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;
 
}
}
   


[解决办法]
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;

}
}

热点排行