Here can be used to 2 kinds of methods, one is to use Preg_match to verify, one is to use JS to judge.
| The code is as follows |
Copy Code |
Preg_match ("/^[0-9a-za-z]+@" ([0-9a-za-z]+) [.]) +[a-z]{2,4}$/i ", $email);
|
| The code is as follows |
Copy Code |
<?php
function Isemail ($email) {
if (Preg_match (/^[0-9a-za-z]+@ ([0-9a-za-z]+) [.]) +[a-z]{2,4}$/i ", $email)) {
Return ' is the mailbox ';
} else{
Return ' not a mailbox ';
}
}
?>
|
or directly using if to judge:
| The code is as follows |
Copy Code |
if (!preg_match (/^[0-9a-za-z]+@ ([0-9a-za-z]+) [.]) +[a-z]{2,4}$/i ", $email)) {
Exit (' ERROR: E-mail format is wrong. <a href= "Javascript:history.back (-1);" > Return </a> ');
}
|
Second, JS judgment method
Myreg =/^ ([a-za-z0-9]+[_|\_|\.]?) *[a-za-z0-9]+@ ([a-za-z0-9]+[_|\_|\.]?) *[a-za-z0-9]+\. [A-za-z] {2,4}$/;
| The code is as follows |
Copy Code |
<script type= "Text/javascript" >
Function Isemail (val) {
var myreg =/^ ([a-za-z0-9]+[_|\_|\.]?) *[a-za-z0-9]+@ ([a-za-z0-9]+[_|\_|\.]?) *[a-za-z0-9]+\. [A-za-z] {2,4}$/;
if (!myreg.test (val))
Return ' not a mailbox ';
Return ' is the mailbox ';
};
Alert (Isemail (' i@julying.com '));
</script>
|
above PHP and JS two methods, according to our actual needs and project use, the old Chiang here used the first method.