var email=prompt("输入邮箱格式");var str=email.lastIndexOf(".");var str2=email.substring(str);//.com/.cnvar str3=email.indexOf("@");var str4=email.substring(0,str3);//拿到@前面必须有字符串var str5=email.substring(str3,str3+1);//拿到@符号了解决var str6=email.substring(str+1);//.后面必须有值var str7=email.substring(str,str+1);//拿到.var str8=email.indexOf(".");var str9=email.substring(str3+1,str8);//@到.之间的内容必须不为空var str10=email.substring(0,str3+1);//拿到[email protected]的值var str11=email.substring(0,str+1);//拿到[email protected]的值var str12=(email.split(".")).length-1;//if((str2==".com"||str2==".cn")&&str4!=""&&str5=="@")if(str5=="@"&&str7=="."&&(str11.length>str10.length)&&str4!=""&&str6!=""&&str9!=""&&(str2==".com"||str2==".cn")&&str12<=2){ alert("邮箱格式正确");}else{ alert("邮箱格式错误");}
时间: 2024-10-15 17:36:05