验证码邮箱检验jsp代码
JS中常用的邮箱验证代码
var index1=EmailString.indexOf("@");
var index2=EmailString.indexOf(".",index1);
var msg="验证邮箱地址实例:\n\n";
msg+="邮箱地址: "+EmailString+"\n";
msg+=" 2、'@'后必须有'.',且中间至少间隔一个字符;\n"
msg+=" 3、'@'不为第一个字符,'.'不为最后一个字符。\n"
}
else
{
msg+="邮箱地址合法!\n\n";
msg+="能同时满足如下条件:\n";
msg+=" 1、邮件地址中同时含有'@'和'.'字符;\n";
msg+=" 2、'@'后必须有'.',且中间至少间隔一个字符;\n"
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"/TR/REC-html140/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
javaScript正则表达式验证邮箱
javaScript正则表达式验证邮箱1 <!DOCTYPE html>2 <html>3 <head>4 <meta charset="UTF-8">5 <title></title>6 </head>7 <script type="text/javascript">8function isEmail(str){9if(str==null) return;1011var reg=new RegExp(/^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/);1213return reg.test(str);//检测字符串是否符合正则表达式14 }1516 (function(){17var str="123abc@";18 document.write(str+"验证结果:"+isEmail(str)+"<br />");1920var str="123_";21 document.write(str+"验证结果:"+isEmail(str)+"<br />");2223var str="haha@";24 document.write(str+"验证结果:"+isEmail(str)+"<br />");2526 })();27 </script>28 <body>29 <div>30 <h3>31正则表达式验证邮箱是否正确,RegExp对象的test()⽅法可以检测某个字符串是否匹配。
JSP javascript脚本 邮箱、密码、用户名验证
<html><head><link rel="stylesheet" type="text/css" href="shiyan2.css" /><script language="javascript" src="shiyan2.js"></script><title>用户注册页面</title></head><body> <form action="shiyan22.html" name="z"><table><tr><td>用户名:</td><th><inputtype="text"onfocus="a2()"></th><th id="message"></th>value=""name="name1"onblur="a1()"</tr><tr><td>密码:</td><th><inputtype="password"value=""name="name2"onblur="a3()"onfocus="a4() "></th><th id="message1"></th><td>确认密码:</td><th><inputtype="password"value=""name="name3"onblur="a5()"onFocus="a6( )"></th><th id="message2"></th></tr><tr><td>Email:</td><th><inputtype="text"value=""name="name4"onblur="a7()"onFocus="a8()"></t h><th id="message3"></th></tr><tr><td colspan="2"><hr /></td></tr><tr><td>性别:</td><th><inputtype="radio"name="dan"value="radiobuttion">男<inputtype="radio" name="dan" value="radiobuttion">女</th></tr><tr><td>所属省份:</td><th><select name="select"><option selected="selected">请选择</option><option>上海</option><option>北京</option><option>苏</option></select></th><td><input type="submit" value="提交" name="提交"></td><th><input type="reset" value="取消" name="取消"></th></tr></table></form></body></html>州// JavaScriptvar q=0;function a1(){x=1.value;if(x.length<6||x.length>10)document.getElementById("message").innerHTML="<fontcolor=redalign=left>*请输入正确的用户名!</font>";else{document.getElementById("message").innerHTML="<fontcolor=green>√</font>";q=1;}}function a2(){if(q==0)document.getElementById("message").innerHTML="<font color=red>*请输入6到10为用户名!</font>";}var y;function a3(){y=if(y.length<6||y.length>20)document.getElementById("message1").innerHTML="<fontcolor=red>*您输入的密码不符合规则!</font>";else{document.getElementById("message1").innerHTML="<fontcolor=green>√</font>";q=2;}}function a4(){if(q!=2)document.getElementById("message1").innerHTML="<font color=red>*请输入6至20位密码</font>";}function a5(){yy=3.value;if(yy!=y)document.getElementById("message2").innerHTML="<fontcolor=red>ⅹ两次输入的密码不一样!</font>";else{document.getElementById("message2").innerHTML="<fontcolor=green>√</font>";q=3;}}function a6(){if(q!=3)document.getElementById("message2").innerHTML="<fontcolor=red>*请在此输入密码</font>";}function a7(){var email = 4.value;var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;chkFlag = pattern.test(email);if(chkFlag){document.getElementById("message3").innerHTML="<fontcolor=green>√</font>";}else{document.getElementById("message3").innerHTML="<fontcolor=red>邮箱格式不正确。
web前端Javascript实现邮箱的简单验证
web前端Javascript实现邮箱的简单验证我们这⾥对输⼊的字符串先设定邮箱的验证规则,⼀个⽐较弱的验证规则:它需要包含“@”、“.”符号,并且“@”符号之前必须要有⾄少1个字符,“@”和“.”也必须有⾄少1个字符,“.”后⾯⾄少有2个字符。
如果验证错误,在后⾯输出红⾊的错误提⽰;如果验证正确,输出绿⾊的正确提⽰。
代码实现如下:<!DOCTYPE html><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"><head></head><body><label>email:</label><input type="text" id="email"/><input type="button" value="验证" onclick="checkemail()" /><span id="message"></span></body><script type="text/javascript">function checkemail() {var obj = document.getElementById("email");if(obj.value != ""){var str = obj.value;if(str.indexOf("@") != -1 && str.indexOf(".") != -1){var a = str.split("@");if(a[0].length > 0){if(a[1].length > 0){var b = a[1].split(".");if(b[0].length > 0){if(b[1].length > 1){document.getElementById("message").innerHTML = "<font color='green'>正确</font>";}else{document.getElementById("message").innerHTML = "<font color='red'>错误,.后⾯必须要有⾄少2个字符</font>";}}else{document.getElementById("message").innerHTML = "<font color='red'>错误,@和.之间必须要有⾄少1个字符</font>";}}else{document.getElementById("message").innerHTML = "<font color='red'>错误,@后⾯必须要有⾄少1个字符</font>";}}else{document.getElementById("message").innerHTML = "<font color='red'>错误,@前⾯必须要有⾄少1个字符</font>";}}else{document.getElementById("message").innerHTML = "<font color='red'>错误,邮箱需要包含@和.字符</font>";}}}</script></html>。
javaScript简单验证代码(用户名,密码,邮箱)
javaScript简单验证代码(⽤户名,密码,邮箱)复制代码代码如下:<script language="javascript">function IsDigit(cCheck){return (('0'<=cCheck) && (cCheck<='9'));}function IsAlpha(cCheck){return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))}function IsaNull(cCheck){return(cCheck != " ")}function checkform(){id = document.sform1.id.value;if (id == ""){alert("请输⼊注册名");document.sform1.id.focus();return false;}for (nIndex=0; nIndex<id.length; nIndex++){cCheck = id.charAt(nIndex);if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.')){alert("⽤户名只能使⽤字母、数字以及-、_和.,并且不能使⽤中⽂");document.sform1.id.focus();return false;}}chineseid = document.sform1.chineseid.value;if (chineseid == ""){alert("请输⼊中⽂昵称");document.sform1.chineseid.focus();return false;}password = document.sform1.password.value;if (password == ""){alert("请输⼊登陆密码");document.sform1.password.focus();return false;}password1 = document.sform1.password1.value;if (password>password1){alert("重复密码与登陆密码不相同");document.sform1.password.focus();document.sform1.password1.focus();return false;}if (password<password1){alert("重复密码与登陆密码不相同");document.sform1.password.focus(); document.sform1.password1.focus();return false;}if (document.sform1.email.value == ""){alert("请输⼊您的E-MAIL地址"); document.sform1.email.focus();return false;}email=document.sform1.email.value; emailerr=0for (i=0; i<email.length; i++){if ((email.charAt(i) == "@") & (email.length > 5)) {emailerr=emailerr+1}}if (emailerr != 1){alert("请输⼊正确的E-MAIL地址"); document.sform1.email.focus();return false;}if (document.sform1.checkask.value==""){alert("密码提⽰问题不能为空"); document.sform1.checkask.focus();return false;}if (document.sform1.checkans.value=="") {alert("您的密码提⽰问题答案不能为空"); document.sform1.checkans.focus();return false;}return true;}</script>。
数据验证JS脚本(手机号码、固定电话、邮政编码、数字验证、两位小数、邮箱、身份证号码等)
/** 数据有效性验证JS脚本*///--身份证号码验证-支持新的带x身份证function isIdCardNo(obj) {var num = obj.value;if(num.length==0){return false;}var factorArr = new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1);var error;var varArray = new Array();var intValue;var lngProduct = 0;var intCheckDigit;var intStrLen = num.length;var idNumber = num;if ((intStrLen != 15) && (intStrLen != 18)) {error = "输入身份证号码长度不对!\n长度必须为15位或18位!";alert(error);obj.value="";obj.focus();return false;}for(i=0;i<intStrLen;i++) {varArray[i] = idNumber.charAt(i);if ((varArray[i] < '0' || varArray[i] > '9') && (i != 17)) {error = "身份证号码中含有不合法字符!";alert(error);obj.value="";obj.focus();return false;} else if (i < 17) {varArray[i] = varArray[i]*factorArr[i];}}if (intStrLen == 18) {var date8 = idNumber.substring(6,14);if (checkDate(date8) == false) {error = "身份证中日期信息不正确!.";alert(error);obj.focus();return false;}for(i=0;i<17;i++) {lngProduct = lngProduct + varArray[i];}intCheckDigit = 12 - lngProduct % 11;switch (intCheckDigit) {case 10:intCheckDigit = 'X';break;case 11:intCheckDigit = 0;break;case 12:intCheckDigit = 1;break;}if (varArray[17].toUpperCase() != intCheckDigit) {//error = "身份证效验位错误!...正确为:" + intCheckDigit + ".";error = "身份证效验位错误!";alert(error);obj.focus();return false;}}else{ //length is 15var date6 = idNumber.substring(6,12);alert(date6);if (checkDate(date6) == false) {alert("身份证日期信息有误!.");obj.focus();return false;}}return true;} //end isIdCardNo-su.kffunction checkDate(date){return true;}//简单验证电话号码是否正确function validatePhone(obj){var objValue = obj.value;if(typeof(objValue)=="undefined")return false;if(objValue=="" || objValue==null){//alert("请输入电话号码!");return false;}var regExp = /^0?\d{11}$/;if(regExp.test(objValue)){return true;}else{alert("电话号码不合法!");obj.value="";obj.focus();return false;}}// 验证联系电话号码是否正确function IsTelephone(obj){var objValue = obj.value;if(typeof(objValue)=="undefined")return false;if(objValue=="" || objValue==null){return false;}varpattern=/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}1[3-9][0-9]{ 9}$)/;if(pattern.test(objValue)) {return true;} else {alert("(1)电话号码由数字、\"(\"、\")\"和\"-\"构成\n(2)电话号码为3到8位\n(3)如果电话号码中包含有区号,那么区号为三位或四位\n(4)区号用\"(\"、\")\"或\"-\"和其他部分隔开\n(5)移动电话号码为11或12位,如果为12位,那么第一位为0");obj.value="";obj.focus();return false;}}// 验证固定电话号码是否正确function IsTel(obj){var objValue = obj.value;if(typeof(objValue)=="undefined")return false;if(objValue=="" || objValue==null){}var pattern=/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)/;if(pattern.test(objValue)) {return true;} else {alert("(1)电话号码由数字、\"(\"、\")\"和\"-\"构成\n(2)电话号码为3到8位\n(3)如果电话号码中包含有区号,那么区号为三位或四位\n(4)区号用\"(\"、\")\"或\"-\"和其他部分隔开。
JS正则表达式验证密码、邮箱格式的实例代码
JS正则表达式验证密码、邮箱格式的实例代码遗憾的是博客内容不允许包含js代码,不能在线测试,就只上代码了<!DOCTYPE html><html><head><meta charset="utf-8"><title>Regular Expression test</title></head><body>⽤户名:(4-16位,字母、下划线、数字,减号) <br/><input type="text" id="un" placeholder="4-16位" ><input type="button" value="test" onclick="userName()" ><span id="one"></span><br/><hr/>密码:(最少6位,⾄少包括⼀个⼤写字母、⼀个⼩写字母、⼀个数字、⼀个特殊字符) <br/><input type="text" id="pw" ><input type="button" value="test" onclick="password()" ><span id="two"></span><br/><hr/>邮箱:(**********)<br/><input type="text" id="em" ><input type="button" value="test" onclick="email()" ><span id="three"></span><br/><hr/>⾝份证号:18位,最后⼀位可以是数字或字母<br/><input type="text" id="idn" ><input type="button" value="test" onclick="idNumber()" ><span id="four"></span><script type="text/javascript">function userName(){var reg=/^\w{4,16}$/;if( !reg.test( document.getElementById("un").value ) )document.getElementById("one").innerHTML="不正确";elsedocument.getElementById("one").innerHTML="正确";}function password(){var reg=/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*?[#?!@$%^&*-]).{6,}$/;if( !reg.test( document.getElementById("pw").value ) )document.getElementById("two").innerHTML="不正确";elsedocument.getElementById("two").innerHTML="正确";}function email(){var reg=/^\w+@[a-zA-Z0-9]{2,10}(?:\.[a-z]{2,4}){1,3}$/;if( !reg.test( document.getElementById("em").value ) )document.getElementById("three").innerHTML="不正确";elsedocument.getElementById("three").innerHTML="正确";}function idNumber(){var reg=/^\d{17}[A-z|0-9]{1}$/;if( !reg.test( document.getElementById("idn").value ) )document.getElementById("four").innerHTML="不正确";elsedocument.getElementById("four").innerHTML="正确";}</script></body></html>总结以上所述是⼩编给⼤家介绍的JS 正则表达式验证密码、邮箱格式的实例代码,希望对⼤家有所帮助,如果⼤家有任何疑问欢迎给我留⾔,⼩编会及时会及时回复⼤家的!。
js验证邮箱、qq号、手机电话
通用JS验证(手机,电话,邮箱,QQ)2010-05-04 18:59//定义邮箱,电话,手机,QQ,税友通验证标志
var email_Flag = false;
var phone_Flag = false;
/^153\d{4,8}$/ //联通153。至少4位,最多8位
/^159\d{4,8}$/ //移动159。至少4位,最多8位
<input type="text" id="xxx" onblur="verifyXxx();" onfocus="clearInfo(document.getElementById('xxx'))" />
var reg = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
if(verifyIsNull(phone_info,strPhone)){
phone_Flag = false;
return ;
}
phone_Flag = reg.test(strPhone);
if(phone_Flag){
phone_info.innerHTML = "恭喜!电话号码输入正确。";
}else{
phone_info.innerHTML = "对不起,您输入的电话号码格式错误。";
}
}
//验证手机号码
function verifyMobile(){
JS中常用的邮箱验证代码
<! DOCTYP E HTML PUBLIC "-//W3C//DTD HTML 4.0//EN""/TR/REC-html140/strict.dtd"><html><head><meta http-equiv="Conten t-Type" conten t="text/html; charse t=gb2312"><title>Sample Page!</title><script langua ge="JavaSc ript" type="text/javasc ript"><!--functi on EmailA ddres sTest(){//获取用户输入的邮箱地址相关信息var EmailS tring=docume nt.MyForm.MyEmai l.value;var strLen gth=EmailS tring.length;var index1=EmailS tring.indexO f("@");var index2=EmailS tring.indexO f(".",index1);var msg="验证邮箱地址实例:\n\n";msg+=" 邮箱地址: "+EmailS tring+"\n";msg+=" 验证信息: ";//返回相关验证信息if(index1==-1||index2==-1||index2<=index1+1||index1==0||index2==strLen gth-1) {msg+="邮箱地址不合法!\n\n"msg+="不能同时满足如下条件:\n";msg+=" 1、邮件地址中同时含有'@'和'.'字符;\n";msg+=" 2、'@'后必须有'.',且中间至少间隔一个字符;\n"msg+=" 3、'@'不为第一个字符,'.'不为最后一个字符。
常用的js验证数字,电话号码,传真,邮箱,...
var reg1 = / ^153\d{4,8}$ / ;
var reg2 = / ^159\d{4,8}$ / ;
var reg3 = / ^0\d{10,11}$ / ;
}
2、电话号码,传真
//校验普通电话、传真号码:可以“+”开头,除数字外,可含有“-”
function isTel(object)
{
//国家代码(2到3位)-区号(2到3位)-电话号码(7到8位)-分机号(3位)"
}
}
}
5、邮编
//校验(国内)邮政编码
function isPostalCode(object)
{
var s =document.getElementById(object.id).value;
var reg1 = /^153\d{4,8}$/;
var reg2 = /^159\d{4,8}$/;
var reg3 = /^0\d{10,11}$/;
var my = false;
if (reg0.test(s))my=true;
object.value="";
object.focus();
}
}
}
4、手机号码
var pattern =/^[0-9]{6}$/;
if(s!="")
{
if(!pattern.exec(s))
{
if (!my)
{
alert('请输入正确的手机号码');
object.value="";
javascript表单验证-邮箱验证
javascript表单验证-邮箱验证<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Title</title><script type="text/javascript">function validate_email(field,text){with (field){// with就是类似C++的namespace,简单说就是命名空间,也就是说with的{}⾥⾯就不⽤再写 thisform.xxx 了,直接写 xxx就是意味着是thisform的//这⾥的value=field.valueapos = value.indexOf("@");//获取“@”出现的位置dotpos = stIndexOf(".");//获取“.”出现的位置if (apos<1||dotpos-apos<2){//做⼀个判断,输⼊的邮箱必须包含“@”符号和点号“.”同时“@”不可以是邮件地址的⾸字符,并且“@”之后需有⾄少⼀个“.”号:alert(text);//如果条件成⽴,则弹出该提⽰框return false;//这⾥的返回false,意味着严重失败}else{alert("提交成功\n\n点击确定继续")//如果条件不成⽴,则弹出该提⽰框return true;//意味着验证成功}}}function validate_form(thisform){//因为onsubmit⾥调⽤了validate_form(this),这⾥的this就是指form本⾝,thisform接收的就是这个form也可以改成formwith (thisform){// with就是类似C++的namespace,简单说就是命名空间,也就是说with的{}⾥⾯就不⽤再写 thisform.xxx 了,直接写 xxx就是意味着是thisform的//这⾥的email=thisform.email=form⾥name=emailif(validate_email(email,"请输⼊正确的邮箱地址")==false){//调⽤ validate_required 参数是thisform下⾯的name=email的标签的引⽤,另外⼀个参数是个字符串 email.focus();//如果validate_email返回false,就把焦点设定到email上return false;//这⾥的返回false,意味着验证失败,表单不会被提交}}}</script></head><body><form action="javascript:;" onsubmit="return validate_form(this)" method="post"><!--当提交表单时,先执⾏validate_form()。
常用的js验证数字
常用的js验证数字,电话号码,传真,邮箱,手机号码,邮编,日期1、数字function testisNum(object){var s =document.getElementById(object.id).value;if(s!=""){if(isNaN(s)){alert("请输入数字");object.value="";object.focus();}}}2、电话号码,传真//校验普通电话、传真号码:可以“+”开头,除数字外,可含有“-”function isT el(object){//国家代码(2到3位)-区号(2到3位)-电话号码(7到8位)-分机号(3位)"var s =document.getElementById(object.id).value;var pattern =/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;//var pattern=/(^[0-9]{3,4}\-[0-9]{7,8}$)|(^[0-9]{7,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/;if(s!=""){if(!pattern.exec(s)){alert('请输入正确的电话号码:电话号码格式为国家代码(2到3位)-区号(2到3位)-电话号码(7到8位)-分机号(3位)"');object.value="";object.focus();}}}3、邮箱function Check(object){var s =document.getElementById(object.id).value;var pattern =/^[a-zA-Z0-9_\-]{1,}@[a-zA-Z0-9_\-]{1,}\.[a-zA-Z0-9_\-.]{1,}$/;if(s!=""){if(!pattern.exec(s)){alert('请输入正确的邮箱地址');object.value="";object.focus();}}}4、手机号码//校验手机号码:必须以数字开头,除数字外,可含有“-”function isMobile(object){var s =document.getElementById(object.id).value;var reg0 = /^13\d{5,9}$/;var reg1 = /^153\d{4,8}$/;var reg2 = /^159\d{4,8}$/;var reg3 = /^0\d{10,11}$/;var my = false;if (reg0.test(s))my=true;if (reg1.test(s))my=true;if (reg2.test(s))my=true;if (reg3.test(s))my=true;if(s!=""){if (!my){alert('请输入正确的手机号码');object.value="";object.focus();}}}//校验日期function isdate(object){var s =document.getElementById(object.id).value;var pattern=/^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2] [0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\ /\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[ \-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[0-9])|([1-2][0-3]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$/;if(s!=""){if(!pattern.exec(s)){alert('请输入正确的日期');object.value="";object.focus();}}}5、邮编//校验(国内)邮政编码function isPostalCode(object){var s =document.getElementById(object.id).value;var pattern =/^[0-9]{6}$/;if(s!=""){if(!pattern.exec(s)){alert('请输入正确的邮政编码');object.value="";object.focus();}}}6、日期//校验日期function isdate(object){var s =document.getElementById(object.id).value;var pattern=/^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2] [0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\ /\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[ \-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[0-9])|([1-2][0-3]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$/;if(s!=""){if(!pattern.exec(s)){alert('请输入正确的日期');object.value="";object.focus();}}}一、清除空格String.prototype.trim = function()//去除空格{return this.replace(/(^[\s]*)|([\s]*$)/g, "");}二、检查一个字符串是否包含特殊字符/*功能:检查传入的字符串中是否包含特殊字符参数:str-要检查的字符串输出:"1"表示字符串不包含特殊字符,验证成功;否则返回"0"相关说明:空字符串可通过验证*/function CheckSpecialString(str){StringFilter = new Array ("'" ,"\\", ".", ",", ";", "/","<","}","%","*");//可以向StringFilter中添加要过滤的字符i=StringFilter.length;j=str.length;for (k=0;k<i;k++){for (m=0;m<j;m++){temp1=str.charAt(m);temp2=StringFilter[k];if (temp1==temp2){return 0;}}}return 1;}三、检查一个字符串是否为中文/*功能:检查传入的字符串是否为中文参数:str-要检查的字符串输出:true表示验证成功,false表示验证不成功相关说明:空字符串可以通过验证,且包含中文的特殊字符*/function IsChineseString(str){var pattern_cn = /^([\u4E00-\u9FA5]|[\uFE30-\uFFA0])*$/gi;if(pattern_cn.test(str)){return true;}else{return false;}}四、检查一个字符串中是否包含全角空格/*功能:检查传入的字符串是否为中文参数:str-要检查的字符串输出:true表示验证成功(不饮食全解空格),false表示验证不成功相关说明:空字符串可以通过验证*/function FullSpace(str){var Reg = /\/;var booleanT = Reg.test(str);if (booleanT == true){return false;}return true;}五、比较两个字符串形式的日期大小/*比较两个字符串形式的日期大小功能:比较两个字符串形式的日期大小参数:firstDate-要检查日期字符串,字符串形式为"2007/05/08"或“2007-05-08”secondDate-要检查的日期字符串,字符串形式为"2007/05/08"或“2007-05-08”输出:true表示第一个日期大于第二个日期,false表示第二个日期大于或等于第一个日期相关说明:空字符串可以通过验证*/function DateExample(firstDate,secondDate){if ( firstDate.indexOf("-") > 0){firstDate = firstDate.replace(/-/g,"/") ;}if ( secondDate.indexOf("-") > 0){secondDate = secondDate.replace(/-/g,"/") ;}var FirstDate = new Date(Date.parse(firstDate)) ;var SecondDate = new Date(Date.parse(secondDate)) ;alert( FirstDate > SecondDate );}六、检查一个字符串是否为一个IP地地/*功能:检查传入的字符串是否为一个IP地址参数:str-要检查的字符串输出:true表示验证成功,false表示验证不成功相关说明:空字符串不可以通过验证*/function CheckIP(str){var Reg =/^([1-9]|[1-9]\d|1\d{2}|2[0-1]\d|22[0-3])(\.(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])){3}$/;var booleanT = Reg.test(str);return booleanT ;}七、整除函数function Div(exp1, exp2){var n1 = Math.round(exp1); //四舍五入var n2 = Math.round(exp2); //四舍五入var rslt = n1 / n2; //除if (rslt >= 0){rslt = Math.floor(rslt); //返回值为小于等于其数值参数的最大整数值。
Jsp学生信息管理系统登录验证全代码
1.jsp登录界面<%@page language="java"contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><html><head><meta http-equiv="Content-Type"content="text/html; charset=UTF-8"><title>用户登录界面</title></head><form action="LoginServlet"method="post"><body bgcolor="blue"><marquee direction="right"onmouseover="stop()" onmouseout="start()"style="font-family: 楷体_GB2312"> <p><font size="10px"color="red">学生信息信息管理系统</font></p></marquee><table align=center width="237"><tr><td><table width=100%><tr><td colspan=6><font size=2><div id="b2bContent"style="FILTER: revealTrans(Duration = 1, Transition = 23); WIDTH: 100%; HEIGHT: 162px"></div></font></td></tr><tr><td align=center STYLE='cursor: hand'><font size=2><div class="b2bbutton"id="bt0"onclick="javascript:showPage(0);clearTimeout(theTime r);theTimer=setTimeout('turnPage()',speed);checkBt();"> 1</div></font></td><td align=center STYLE='cursor: hand'><font size=2><div class="b2bbutton"id="bt1"onclick="javascript:showPage(1);clearTimeout(theTime r);theTimer=setTimeout('turnPage()',speed);checkBt();"> 2</div></font></td><td align=center STYLE='cursor: hand'><font size=2><div class="b2bbutton"id="bt2"onclick="javascript:showPage(2);clearTimeout(theTime r);theTimer=setTimeout('turnPage()',speed);checkBt();"> 3</div></font></td><td align=center STYLE='cursor: hand'><font size=2><div class="b2bbutton"id="bt3"onclick="javascript:showPage(3);clearTimeout(theTime r);theTimer=setTimeout('turnPage()',speed);checkBt();"> 4</div></font></td><td align=center STYLE='cursor: hand'><font size=2><div class="b2bbutton"id="bt4"onclick="javascript:showPage(4);clearTimeout(theTime r);theTimer=setTimeout('turnPage()',speed);checkBt();">5</div></font></td><td align=center STYLE='cursor: hand'><font size=2><div class="b2bbutton"id="bt5"onclick="javascript:showPage(5);clearTimeout(theTime r);theTimer=setTimeout('turnPage()',speed);checkBt();"> 6</div></font></td></tr></table><script language="javascript">b2bStr = new Array();b2bStr[0]= "<div style='float:left; width:100%;overflow:hidden;'><a href= target=_blank><img src= width=214px height=145px border=0></a><br><a target=_blank title=太阳岛公园一角 href=>太阳岛公园一角</a></div>";b2bStr[1] = "<div style='float:left; width:100%;overflow:hidden;'><a href= target=_blank><img src= width=214px height=145px border=0></a><br><atarget=_blank title=太阳岛公园湖光山色 href=>太阳岛公园湖光山色</a></div>";b2bStr[2] = "<div style='float:left; width:100%;overflow:hidden;'><a href= target=_blank><img src= width=214px height=145px border=0></a><br><a target=_blank title=哈尔滨雪雕href=>哈尔滨雪雕</a></div>";b2bStr[3] = "<div style='float:left; width:100%;overflow:hidden;'><a href= target=_blank><img src= width=214px height=145px border=0></a><br><a target=_blank title=镜泊湖 href=>镜泊湖</a></div>";b2bStr[4] = "<div style='float:left; width:100%;overflow:hidden;'><a href= target=_blank><img src= width=214px height=145px border=0></a><br><a target=_blank title=太阳岛公园瀑布 href=>太阳岛公园瀑布</a></div>";b2bStr[5] = "<div style='float:left; width:100%;overflow:hidden;'><a href= target=_blank><img src= width=214px height=145px border=0></a><br><a target=_blank title=镜泊湖夜色href=>镜泊湖夜色</a></div>";var page=0;var speed=3000;function showPage(id){page=id;setTransition();=b2bStr[id];}function turnPage(){showPage(page);theTimer=setTimeout("turnPage()", speed);checkBt();page++;if(page>=6) page=0;}function checkBt(){for(var i=0;i<6;i++){btObj=eval('bt'+i);if(page==i){'#FFFFFF';'#FF781C';}else{'#000000';'#F7F7F7';}}}function setTransition(){}turnPage();</script></TD></TR></table><hr color="green"width="540"><table align="center"><tr><td>用户名:<input type="text"name="username" size="8"maxlength="6"></td></tr><tr><td>密 码:<input type="password"name="password"size="10" maxlength="6"></td></tr><tr><td><input type="submit"value="登录"> <input type="reset"value="取消"></td></tr></table></form></body></html>代码(1) 定义的属性和数据库中的字段相对应package class User {private int id;private String username;private String password;private String xh;private String college;public int getId(){return id;}public void setId(int id){= id;}public String getUsername() {return username;}public void setUsername(String username) { = username;}public String getPassword() {return password;}public void setPassword(String password) { = password;}public String getXh() {return xh;}public void setXh(String xh) {= xh;}public String getCollege() {return college;}public void setCollege(String college) { = college;}}(2) 操作数据库tb_user,验证用户登录package class UserDAO {/***验证用户登录*@return*/public boolean checkDenglu(User user) { boolean flag = false;etAttribute("user", user);}else{message ="对不起密码错误,请重新输入!";path="";}rite(message);*/orward(request,response);}}。
js表单验证代码大全
关键字:js验证表单大全,用JS控制表单提交 ,javascript提交表单:目录:1:js 字符串长度限制、判断字符长度、js限制输入、限制不能输入、textarea 长度限制2.:js判断汉字、判断是否汉字、只能输入汉字3:js判断是否输入英文、只能输入英文4:js只能输入数字,判断数字、验证数字、检测数字、判断是否为数字、只能输入数字5:只能输入英文字符和数字6: js email验证、js 判断email 、信箱/邮箱格式验证7:js字符过滤,屏蔽关键字8:js密码验证、判断密码2.1: js 不为空、为空或不是对象、判断为空、判断不为空2.2:比较两个表单项的值是否相同2.3:表单只能为数字和"_",2.4:表单项输入数值/长度限定2.5:中文/英文/数字/邮件地址合法性判断2.6:限定表单项不能输入的字符2.7表单的自符控制2.8:form文本域的通用校验函数1. 长度限制<script>function test(){if(document.a.b.value.length>50){alert("不能超过50个字符!");document.a.b.focus();return false;}}</script><form name=a onsubmit="return test()"><textarea name="b" cols="40" wrap="VIRTUAL" rows="6"></textarea><input type="submit" name="Submit" value="check"></form>2. 只能是汉字<input onkeyup="value="/oblog/value.replace(/[^\u4E00-\u9FA5]/g,'')"> 3." 只能是英文<script language=javascript>function onlyEng(){if(!(event.keyCode>=65&&event.keyCode<=90))event.returnvalue=false;}</script><input onkeydown="onlyEng();">4. 只能是数字<script language=javascript>function onlyNum(){if(!((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&even t.keyCode<=105)))//考虑小键盘上的数字键event.returnvalue=false;}</script><input onkeydown="onlyNum();">5. 只能是英文字符和数字<input onkeyup="value="/oblog/value.replace(/[\W]/g,"'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('t ext').replace(/[^\d]/g,''))">6. 验证油箱格式<SCRIPT LANGUAGE=javascript RUNAT=Server>function isEmail(strEmail) {if(strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)return true;elsealert("oh");}</SCRIPT><input type=text onblur=isEmail(this.value)>7. 屏蔽关键字(这里屏蔽***和****)<script language="javascript1.2">function test() {if((a.b.value.indexOf ("***") == 0)||(a.b.value.indexOf ("****") == 0)){ alert(":)");a.b.focus();return false;}}</script><form name=a onsubmit="return test()"><input type=text name=b><input type="submit" name="Submit" value="check"></form>8. 两次输入密码是否相同<FORM METHOD=POST ACTION=""><input type="password" id="input1"><input type="password" id="input2"><input type="button" value="test" onclick="check()"></FORM><script>function check(){with(document.all){if(input1.value!=input2.value){alert("false")input1.value = "";input2.value = "";}else document.forms[0].submit();}}</script>够了吧 :)屏蔽右键很酷oncontextmenu="return false" ondragstart="return false" onselectstart="return false"加在body中二2.1 表单项不能为空<script language="javascript"><!--function CheckForm(){if (.value.length == 0) {alert("请输入您姓名!");.focus();return false;}return true;}--></script>2.2 比较两个表单项的值是否相同<script language="javascript"><!--function CheckForm()if (document.form.PWD.value != document.form.PWD_Again.value) { alert("您两次输入的密码不一样!请重新输入.");document.ADDUser.PWD.focus();return false;}return true;}--></script>2.3 表单项只能为数字和"_",用于电话/银行帐号验证上,可扩展到域名注册等<script language="javascript"><!--function isNumber(String){var Letters = "1234567890-"; //可以自己增加可输入值var i;var c;if(String.charAt( 0 )=='-')return false;if( String.charAt( String.length - 1 ) == '-' )return false;for( i = 0; i < String.length; i ++ ){c = String.charAt( i );if (Letters.indexOf( c ) < 0)return false;}return true;}function CheckForm(){if(! isNumber(document.form.TEL.value)) {alert("您的电话号码不合法!");document.form.TEL.focus();return false;}return true;}--></script>2.4 表单项输入数值/长度限定<script language="javascript"><!--function CheckForm(){if (document.form.count.value > 100 || document.form.count.value < 1) {alert("输入数值不能小于零大于100!");document.form.count.focus();return false;}if (document.form.MESSAGE.value.length<10){alert("输入文字小于10!");document.form.MESSAGE.focus();return false;}return true;}//--></script>2.5 中文/英文/数字/邮件地址合法性判断<SCRIPT LANGUAGE="javascript"><!--function isEnglish(name) //英文值检测{if(name.length == 0)return false;for(i = 0; i < name.length; i++) {if(name.charCodeAt(i) > 128)return false;}return true;}function isChinese(name) //中文值检测{if(name.length == 0)return false;for(i = 0; i < name.length; i++) {if(name.charCodeAt(i) > 128)return true;}return false;}function isMail(name) // E-mail值检测{if(! isEnglish(name))return false;i = name.indexOf(" at ");j = name dot lastIndexOf(" at ");if(i == -1)return false;if(i != j)return false;if(i == name dot length)return false;return true;}function isNumber(name) //数值检测{if(name.length == 0)return false;for(i = 0; i < name.length; i++) {if(name.charAt(i) < "0" || name.charAt(i) > "9") return false;}return true;}function CheckForm(){if(! isMail(form.Email.value)) {alert("您的电子邮件不合法!");form.Email.focus();return false;}if(! isEnglish(.value)) {alert("英文名不合法!");.focus();return false;}if(! isChinese(name.value)) {alert("中文名不合法!");name.focus();return false;}if(! isNumber(form.PublicZipCode.value)) {alert("邮政编码不合法!");form.PublicZipCode.focus();return false;}return true;}//--></SCRIPT>2.6 限定表单项不能输入的字符<script language="javascript"><!--function contain(str,charset)// 字符串包含测试函数{var i;for(i=0;i<charset.length;i++)if(str.indexOf(charset.charAt(i))>=0)return true;return false;}function CheckForm(){if ((contain(.value, "%\(\)><")) || (contain(document.form.MESSAGE.value, "%\(\)><"))) {alert("输入了非法字符");.focus();return false;}return true;}//--></script>1. 检查一段字符串是否全由数字组成---------------------------------------<script language="Javascript"><!--function checkNum(str){return str.match(/\D/)==null} alert(checkNum("1232142141"))alert(checkNum("123214214a1"))// --></script>2. 怎么判断是否是字符---------------------------------------if (/[^\x00-\xff]/g.test(s)) alert("含有汉字");else alert("全是字符");3. 怎么判断是否含有汉字---------------------------------------if (escape(str).indexOf("%u")!=-1) alert("含有汉字"); else alert("全是字符");4. 邮箱格式验证//函数名:chkemail//功能介绍:检查是否为Email Address//参数说明:要检查的字符串//返回值:0:不是 1:是function chkemail(a){ var i=a.length;var temp = a.indexOf('@');var tempd = a.indexOf('.');if (temp > 1) {if ((i-temp) > 3){if ((i-tempd)>0){return 1;}}}return 0;}5. 数字格式验证--------------------------------------- //函数名:fucCheckNUM//功能介绍:检查是否为数字//参数说明:要检查的数字//返回值:1为是数字,0为不是数字function fucCheckNUM(NUM){var i,j,strTemp;strTemp="0123456789";if ( NUM.length== 0)return 0for (i=0;i<NUM.length;i++){j=strTemp.indexOf(NUM.charAt(i));if (j==-1){//说明有字符不是数字return 0;}}//说明是数字return 1;}6. 电话号码格式验证//函数名:fucCheckTEL//功能介绍:检查是否为电话号码//参数说明:要检查的字符串//返回值:1为是合法,0为不合法function fucCheckTEL(TEL){var i,j,strTemp;strTemp="0123456789-()# ";for (i=0;i<TEL.length;i++){j=strTemp.indexOf(TEL.charAt(i));if (j==-1){//说明有字符不合法return 0;}}//说明合法return 1;}7. 判断输入是否为中文的函数--------------------------------------- function ischinese(s){var ret=true;for(var i=0;i<s.length;i++)ret=ret && (s.charCodeAt(i)>=10000); return ret;}8. 综合的判断用户输入的合法性的函数--------------------------------------- <script language="javascript">//限制输入字符的位数开始//m是用户输入,n是要限制的位数function issmall(m,n){if ((m<n) && (m>0)){return(false);}else{return(true);}}9. 判断密码是否输入一致function issame(str1,str2){if (str1==str2){return(true);}else{return(false);}}10. 判断用户名是否为数字字母下滑线---------------------------------------function notchinese(str){var reg=/[^A-Za-z0-9_]/gif (reg.test(str)){return (false);}else{return(true); }}2.8. form文本域的通用校验函数---------------------------------------作用:检测所有必须非空的input文本,比如姓名,账号,邮件地址等等。
JS邮箱验证-正则验证
JS邮箱验证-正则验证1 <form action="">2 输⼊:<input type="text" name="mazey" id="mazey" placeholder="请输⼊邮箱">3 <input type="button" value="验证" onclick="check();">4 </form>56 <script>7function check(){8 var reg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$"); //正则表达式 9 var obj = document.getElementById("mazey"); //要验证的对象10 if(obj.value === ""){ //输⼊不能为空11 alert("输⼊不能为空!");12 return false;13 }else if(!reg.test(obj.value)){ //正则验证不通过,格式不对14 alert("验证不通过!");15 return false;16 }else{17 alert("通过!");18 return true;19 }20 }21 </script>2223⼀、RegExp2425 1.1 创建RegExp对象2627new RegExp("必选,正则表达式","可选,匹配模式g,i,m")28 1.2 RegExp对象的⽅法2930 test:检索字符串中的指定值,返回True或False。
jsp验证码代码
jsp验证码代码在开发中验证码是比较常用到有效防止这种问题对某一个特定注册用户用特定程序破解方式进行不断的登陆尝试的方式。
此演示程序包括三个文件:1.login.jsp:登录页面2.code.jsp:生成验证码图片页面3.check.jsp:验证结果code.jsp程序代码 ==================================================<%@ page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*" %><%// 在内存中创建图象int width=60, height=20;BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);// 获取图形上下文Graphics g = image.getGraphics();// 设定背景色g.setColor(new Color(0xDCDCDC));g.fillRect(0, 0, width, height);//画边框g.setColor(Color.black);g.drawRect(0,0,width-1,height-1);// 随机产生的认证码(4位数字)String rand =""+ (Math.random()*10000);rand = rand.substring(0,rand.indexOf("."));switch(rand.length()){case 1: rand = "000"+rand; break;case 2: rand = "00"+rand; break;case 3: rand = "0"+rand; break;default: rand = rand.substring(0,4); break;}// 将认证码存入SESSIONsession.setAttribute("rand",rand);// 将认证码显示到图象中g.setColor(Color.black);Integer tempNumber = new Integer(rand);String numberStr = tempNumber.toString();g.setFont(new Font("Atlantic Inline",Font.PLAIN,18));String Str = numberStr.substring(0,1);g.drawString(Str,8,17);Str = numberStr.substring(1,2);g.drawString(Str,20,15);Str = numberStr.substring(2,3);g.drawString(Str,35,18);Str = numberStr.substring(3,4);g.drawString(Str,45,15);// 随机产生88个干扰点,使图象中的认证码不易被其它程序探测到Random random = new Random();for (int i=0;i<20;i++){int x = random.nextInt(width);int y = random.nextInt(height);g.drawOval(x,y,0,0);}// 图象生效g.dispose();// 输出图象到页面ImageIO.write(image, "JPEG", response.getOutputStream());//在页面上调用 <img src="/yourPath/checkNum.jsp" />%>login.jsp程序代码 ==================================================<%@ page contentType="text/html;charset=gb2312" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><title>认证码输入页面</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"><META HTTP-EQUIV="Cache-Control" CONTENT="no-cache"><META HTTP-EQUIV="Expires" CONTENT="0"></head><body><form method=post action="check.jsp"><table><tr><td align=left>系统产生的认证码:</td><td><img border=0 src="code.jsp"></td></tr><tr><td align=left>输入上面的认证码:</td><td><input type=text name=rand maxlength=4 value=""></td></tr><tr><td colspan=2 align=center><input type=submit value="提交检测"></td> </tr></form></body></html>check.jsp程序代码 ==================================================<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %><html><head><title>认证码验证页面</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"><META HTTP-EQUIV="Cache-Control" CONTENT="no-cache"><META HTTP-EQUIV="Expires" CONTENT="0"></head><body><%String rand = (String)session.getAttribute("rand"); String input = request.getParameter("rand");%>系统产生的认证码为: <%= rand %><br>您输入的认证码为: <%= input %><br><br><%if (rand.equals(input)) {%><font color=green>输入相同,认证成功!</font><%} else {%><font color=red>输入不同,认证失败!</font><%}%></body></html>。
获取验证码效果和后台代码(js+html+cs)
获取验证码效果和后台代码(js+html+cs)客户端js+html代码<script type="text/javascript">var tcode = 0;//定时器返回代码 //获得验证码function GetVerifyCodeAction() {var email = $("#email").val();if (!checkEmail(email)) {$("#area_error").addClass("log-tips").show().text(EmailFormatIsFault);//邮箱格式错误}else {$.ajax({type: "post",async: false,url: "/Handler/SendMsgToMail.ashx",data: { op: 12, email: email },success: function (result) {var data = parseInt(result);switch (data) {case 1:$("#area_error").addClass("log-tips").show().text(CheckVerifyCode);//验证码已发送,请注意查收$("#btnSendCode").removeAttr("onclick");//移除发送验证码的click事件tcode = setInterval("ReSend()", 1000);//设置定时器,60秒后容许再次发送break;case -1:$("#area_error").addClass("log-tips").show().text(FillEmail);//请输⼊邮箱break;case -2:$("#area_error").addClass("log-tips").show().text(MailNotReg);//邮箱尚未注册break;case -3:$("#area_error").addClass("log-tips").show().text(OperateException);//操作异常break;case -4:$("#area_error").addClass("log-tips").show().text(OperateException);//操作异常break;case -5:$("#area_error").addClass("log-tips").show().text(OnceMinute);//每分钟只能发送⼀次break;default:$("#area_error").addClass("log-tips").show().text(OperateException);//操作异常break;}}});}return false;} //点击进⼊下⼀步function GoNext() {$("#area_error").removeClass("log-tips").text("").hide();var email = $("#email").val();if (!checkEmail(email)) {$("#area_error").addClass("log-tips").show().text(EmailFormatIsFault);//邮箱格式不正确return false;}var vcode = $("#verify").val();if (vcode == "") {$("#area_error").addClass("log-tips").show().text(FillVerifyCode);//请输⼊验证码return false;} //判断验证码是否正确$.ajax({type: "post",url: "/Handler/Members.ashx",data: { op: 14, email: email, vcode: vcode },success: function (result) {if (result == "-1") {$("#area_error").addClass("log-tips").show().text(VCodeIsNotAvailable);//验证码已失效}if (result == "1") {window.location = "forgot_password.aspx?email=" + email + "&vcode=" + vcode;}}});} //定时器function ReSend() { var Wait60Second="60秒后重发";var TotalCount = $("#hf_timecount").val();TotalCount = TotalCount - 1;$("#hf_timecount").val(TotalCount);if (TotalCount == 0) {ReSetSendMail();}else {$("#btnSendCode").text(Wait60Second.replace("60", TotalCount));}} //重新附加发送邮箱事件function ReSetSendMail() {clearInterval(tcode);$("#hf_timecount").val("60");$("#btnSendCode").text("获取验证码");$("#btnSendCode").attr("onclick", "GetVerifyCodeAction()");}</script><input id="hf_timecount" value="60" type="hidden" /><input type="text" name="email" id="email" /><button type="button" id="btnSendCode" onclick="GetVerifyCodeAction()">获取验证码</button> <input type="text" name="verify" id="verify" /><input type="button" id="btn_next" value="下⼀步" onclick="GoNext()"/>服务端代码:/// <summary>/// 发送邮件/// </summary>/// <param name="context"></param>/// <returns></returns>public string SendMail(HttpContext context){try{if (!string.IsNullOrEmpty(CookiesHelper.getCookie("send_mail_limit"))){return "-5";//每分钟只能发送⼀次}string email = context.Request["email"];if (string.IsNullOrEmpty(email) || !CommonHelper.IsValidEmail(email)){return "-1";//传值为空}//判断邮件是否存在BLL.Web.Member bllMember = new BLL.Web.Member();int mailCount = bllMember.GetCountByEmail(email);Models.Web.Member member = bllMember.GetModelByEmail(email);if (mailCount == 0 || member == null){return "-2";//不存在}string vcode = CommonHelper.RandCode(8);Models.Web.VerifyCode model = new Models.Web.VerifyCode();model.v_code = vcode;model.v_createdate = DateTime.Now;model.v_enddate = DateTime.Now.AddHours(2);model.v_status = 0;model.v_email = email;BLL.Web.VerifyCode bllVC = new BLL.Web.VerifyCode();int no = bllVC.Append(model);if (no > 0){string sendText = "";string tempPath = context.Server.MapPath("~/EmailTemp/ModifyPwd.txt");using (StreamReader sr = new StreamReader(tempPath)){sendText = sr.ReadToEnd();}sendText = sendText.Replace("{UserName_CH}", member.PersnalName);sendText = sendText.Replace("{UserName_EN}", member.PersnalName);sendText = sendText.Replace("{VCode}", vcode);CommonHelper.SendEmail(email, sendText, ng.RetrievePassword); CookiesHelper.setCookie("send_mail_limit", "SendMail", 1.00);}else{return "-3";//验证码⽣成异常,请重试! }return "1";//成功}catch (Exception){return "-4";//异常}}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
var authenNum = $("#tbAuthenCode").val();
var authenId = $("#span_comment_test").html();
$("#lnkRereshAuthenCode").html("<span style='color:red'>刷新中...</span>");
return false;
}
function RefreshImg(response){
$("#imgAuthenCode").attr("src","/Modules/CaptchaImage/ValidCodeImage.aspx?id="+encodeURIComponent(response));
ShowCommentMsg(data.d["ReturnData"]);//"抱歉!评论提交失败!请与管理员联系。");
$("#span_comment_posted").html('');
}
// AjaxPost("/ws/CommentService.asmx/RefreshAuthenCode","{}",ShowAuthenCodeOk);
//}
$("#wrapAuthenCode").show();
}
var comment = {};
comment.authenNum = authenNum;
comment.authenId= authenId;
comment.parentId = 0;
comment.blogId = 0;
$("#tbAuthenCode").val("");
CommentNotify(data.d["CommentID"]);
}
else {
if($("#wrapAuthenCode").css("display")=="none"){
ShowAuthenCode();
$("#tip_AuthenCode").css("color","red");
$("#tip_AuthenCode").html("请输入验证码!");
<SCRIPT type=text/javascript>
var commentAuthorHasChecked = false;
var commentAuthorIsValid = false;
var commentUrlIsValid = true;
var commentEmailIsValid = true;
$("#tip_AuthenCode").html('');
}
function CheckAuthor(isOnblur){
commentAuthorHasChecked = true;
var maxLength = 30;
}
if ($("#span_comment_posted").html()!='' && $("#span_comment_posted").html()==content){
alert("该评论已发表过!");
return;
}
if(!commentEmailIsValid){
isValid = false;
}
if(!CheckCommentContent()){
isValid = false;
//alert(xhr.responseText);
}
} ); Fra bibliotek } function RefreshAuthenCode(){
AjaxPost("/ws/CommentService.asmx/RefreshAuthenCode","{}",RefreshImg);
}
if(!authenCodeIsValid){
isValid = false;
}
if(!hasLogined && !commentUrlIsValid){
isValid = false;
isValid = false;
}
if(!hasLogined && !commentAuthorHasChecked){
CheckAuthor();
}
},
error: function(xhr) {
ShowCommentMsg("抱歉!评论提交失败!请与管理员联系。");
$("#span_comment_posted").html('');
$("#span_comment_test").html(response);
$("#lnkRereshAuthenCode").html("看不清,换一个");
}
function ShowAuthenCode(){
//if($("#wrapAuthenCode").css("display")=="none"){
if(!hasLogined && !commentAuthorIsValid){
isValid = false;
}
if(!authenCodeHasChecked){
CheckAuthenCode();
$("#divCommentShow").html($("#divCommentShow").html()+data.d["ReturnData"]);
$("#tip_AuthenCode").html('');
RefreshAuthenCode();
comment.email = email;
comment.title = '';
comment.content = content;
comment.parentCommentId = $("#span_parentcomment_id").html();
var authenCodeHasChecked = false;
var authenCodeIsValid = true;
var hasLogined = false;
function PostComment() {
var isValid = true;
}
if(!isValid){
return;
}
var content = $("#tbCommentBody").val();
if(content.length>2000){
alert("评论内容过长!不允许发布!");
contentType: "application/json; charset=utf8",
success: function(data) {
if (data.d["IsSuccess"]) {
ShowCommentMsg("感谢您的回复:)");
//RereshComments2(comment.parentId);
$("#tbCommentBody").val('');
//$("#divCommentShow").html(data.d["ReturnData"]+content.replace(/\n/g,"<br/>")+"<br/><br/>");
return;
}
if(content.indexOf(" E E E ")>=0){
alert("该内容不允许布!");
return;
function ShowAuthenCodeOk(response){
UpdateAuthenCode();
$("#tbAuthenCode").val("");
$("#wrapAuthenCode").show();
comment.sourceUrl = '';
comment.author = $("#tbCommentAuthor").val();
comment.url = $("#tbCommentAuthorUrl").val();
comment.authenCode = $("#tbAuthenCode").val();