我新的PHP和我的公司給我登記表的任務, 我想知道如何使用PHP來驗證電子郵件地址(不與JavaScript) 像那裏必須一個。和@ sign 我已經使用JavaScript完成了,但TL表示它必須使用PHP。 我的Html代碼如下 可以幫助嗎?
<html>
<head><title>Form validation</title>
<script type="text/javascript">
/*function validateEmail() {
var emailText = document.getElementById('email').value;
var pattern = /^[a-zA-Z0-9\-_]+(\.[a-zA-Z0-9\-_]+)*@[a-z0-9]+(\-[a-z0-9]+)*(\.[a-z0-9]+(\-[a-z0-9]+)*)*\.[a-z]{2,4}$/;
if (pattern.test(emailText)) {
return true;
} else {
alert('Bad email address: ' + emailText);
return false;
}
}
window.onload = function() {
document.getElementById('email_form').onsubmit = validateEmail;
}
*/
</script>
</head>
<body>
<form action="<?php echo base_url();?>index.php/validation_control/insert_to_db" method="post" id="email_form" onsumbit="return myFunction()">
<table align="center" border="2">
<tr><td>Username :- <td><input type="text" name='uname'/></td></td></tr>
<tr><td>First Name :- <td><input type="text" name='fname'/></td></td></tr>
<tr><td>Last Name :- <td><input type="text" name='lname'/></td></td></tr>
<tr><td>Email :- <td><input type="text" name='email' /><?php //echo $emailErr;?></td></td></tr>
<tr><td>Password :-<td><input type="password" name='pass' id='pass'/></td></td></tr>
<tr><td>Confirm Password :-<td><input type="password" name='cnfpass' id='cnfpass'/></td></td></tr>
<tr><td>Status :-<td><input type="radio" name="status" value="active" />Active<input type="radio" name="status" value="deactive" />Deactive<input type="radio" name="status" value="delete" />Delete</td></td></tr>
<tr><td align="center" colspan="2"><input type="submit" name="sbmt" id="sbmt" value="Submit" onclick="Javscript:validateEmail"/></td></tr>
</table>
</form>
</body>
</html>
? –
顯示你的代碼到目前爲止你已經嘗試 – vishnu