检测表单函数

该博客提供了用JavaScript编写的代码,包含检测邮件格式的函数Is_Email,可判断邮件格式是否正确;还提供了表单验证函数form1_onsubmit,能对姓名、出生日期、工作年限等表单内容进行验证,确保信息完整且邮箱格式正确。

<SCRIPT LANGUAGE=javascript>
<!--
//检测邮件格式
function Is_Email(item){
 var etext
 var elen
 var i
 var aa
 etext=item
 elen=etext.length
 if (elen<5)
  return true;
 i= etext.indexOf("@",0)
 if (i==0 || i==-1 || i==elen-1)
  return true;
 else
 {
  if (etext.indexOf("@",i+1)!=-1)
  return true;
 }
 if (etext.indexOf("..",i+1)!=-1)
  return true;
 i=etext.indexOf(".",0)
 if (i==0 || i==-1 || etext.charAt(elen-1)=='.')
  return true;
 if ( etext.charAt(0)=='-' ||  etext.charAt(elen-1)=='-')
  return true;
 if ( etext.charAt(0)=='_' ||  etext.charAt(elen-1)=='_')
  return true;
 for (i=0;i<=elen-1;i++)
 {
  aa=etext.charAt(i)
  if (!((aa=='.') || (aa=='@') || (aa=='-') ||(aa=='_') || (aa>='0' && aa<='9') || (aa>='a' && aa<='z') || (aa>='A' && aa<='Z')))
   return true;
 }
 return;
}

//检测表单

function form1_onsubmit() {
 
 if ((document.form1.username.value)=="")
 {
  window.alert("姓名不能为空!");
  document.form1.username.focus();
  return (false);
 }
 
 if ((document.form1.birthday.value)=="")
 {
  window.alert("出生日期不能为空!");
  document.form1.birthday.focus();
  return (false);
 }

 if ((document.form1.workyear.value)=="")
 {
  window.alert("工作年限不能为空!");
  document.form1.workyear.focus();
  return (false);
 }
 if ((document.form1.knowledge.value)=="")
 {
  window.alert("学历不能为空!");
  document.form1.knowledge.focus();
  return (false);
 }
 
 if (Is_Email(document.form1.email.value))
 {
  window.alert("你的邮箱的格式不对或为空");
  document.form1.email.focus();
  return (false);
 }
  if ((document.form1.money.value)=="")
 {
  window.alert("期望工资不能为空!");
  document.form1.money.focus();
  return (false);
 }
 
 if ((document.form1.workname.value)=="")
 {
  window.alert("请选择应聘职位!");
  document.form1.workname.focus();
  return (false);
 }
 document.form1.submit();
}

 

//-->
</SCRIPT>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值