| Code Perl |
sub tstEmail {local($x) = @_;
if ($x eq '') {return 1}
while(true) {
if ($x!~/^([\w_\-]+)/) {return 1}; if ($x eq $1) {last}; $x = substr($x,length($1));
if ($x eq '.') {return 1}; if (substr($x,0,1) ne '.') {last}; $x = substr($x,1)
}
if ($x eq '@') {return 1}; if (substr($x,0,1) ne '@') {return 1}; $x = substr($x,1);
if (index($x,'.')==-1) {return 1};
if (substr($x,0,1) eq '[') {
if ($x!~/^(\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])/) {return 1}; if ($x ne $1) {return 1}
} else {
while(true) {
if ($x!~/^([\w_\-]+)/) {return 1}; if ($x eq $1) {last}; $x = substr($x,length($1));
if ($x eq '.') {return 1}; if (substr($x,0,1) ne '.') {last}; $x = substr($x,1)
}
if ($x!~/^([a-zA-Z]{2,})/) {return 1}; if ($x ne $1) {return 1}
}
return 0
}
|
| Code JavaScript |
function tstEmail(x) {
if (x=='') {return 1}
while(true) {
if (!x.match(/^([\w_\-]+)/)) {return 1}; if (x==RegExp.$1) {break}; x = x.substr(RegExp.$1.length);
if (x=='.') {return 1}; if (x.substr(0,1)!='.') {break}; x = x.substr(1)
}
if (x=='@') {return 1}; if (x.substr(0,1)!='@') {return 1}; x = x.substr(1);
if (x.indexOf('.')==-1) {return 1};
if (x.substr(0,1)=='[') {
if (!x.match(/^(\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])/)) {return 1}; if (x!=RegExp.$1) {return 1}
} else {
while(true) {
if (!x.match(/^([\w_\-]+)/)) {return 1}; if (x==RegExp.$1) {break}; x = x.substr(RegExp.$1.length);
if (x=='.') {return 1}; if (x.substr(0,1)!='.') {break}; x = x.substr(1)
}
if (!x.match(/^([a-zA-Z]{2,})/)) {return 1}; if (x!=RegExp.$1) {return 1}
}
return 0
}
|