c#email格式不正确,检查提交的电子邮件格式是否正确

I've created this script to check form of email user will enter into textbox

function checkEmail() {

var mail = document.getElementById('mail');

var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; /* regex koda najdena na codeproject.com*/

if (!filter.test(mail.value))

{

alert('enter valid email');

mail.focus;

return false;

}

It's used to check form in this script and suposed to show you alert, before you are able to continue

$flag = 0;

if(isset($_POST['submit']))

{

$con = mysql_connect("localhost","root","");

if (!$con){

die("cannot connect: " . mysql_error());

}

mysql_select_db("strek", $con);

$nar_db="SELECT * FROM narocniki;";

$result = mysql_query($nar_db, $con);

while($row=mysql_fetch_array($result))

{

if($_POST['mail']==$row['mail'])

$flag = 1;

}

if($flag==0)

{

$sql = "INSERT INTO narocniki (mail) VALUE ('$_POST[mail]')";

mysql_query($sql, $con);

mysql_close($con);

?>

Tvoj mail je bil uspešno sprejet!

}

else

{

echo '

Naveden mail je že v bazi naročnikov!

';

?>

}

}

else

{

include("vsebina/tabdog.html");

?>

naroči se na najnovejše novice

vnesi svoj e-naslov:

}

?>

It's probably just something missing

Should I rather just include script inside the code, and where would be the best to place it-weather directly in head or rather somewhere in between

Is this even possible in my code, because it already checks if mail exists in database, and would then also need to check the form of email

解决方案

Instead of doing it in the onclick attribute of the submit button, try doing it in the onsubmit attribute of the form:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值