Greetings for the day,
I am new to php and my company gave me a task of registration form, i want to know how to validate email address using php(not with JavaScript) like there will must a one . and @ sign i have done t using JavaScript but TL said that it must be using PHP. My Html code is given below can any one help??
<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>