regex email validation yourdomain.com javascript code example
Example 1: email regex javascript
/* JavaScript: validating email address */
isValidEmail("[email protected]"); // true
function isValidEmail(email) {
var emailRegex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
return !!email && typeof email === 'string'
&& email.match(emailformat)};
};
Example 2: validate email function
sub Validate_Email($)
{
my $sEmail = $_[0];
my $sRetMsg = "";
my $sUserNmRegex = "^[[:alnum:]]+([.!#\$\%&'*+-\/=?^_'{|]?[[:alnum:]]+)*";
my $sDomainRegex = "@[[:alnum:]]+([.-]{1}[[:alnum:]]+)*";
my $sEndRegex = "([.]{1}[[:alnum:]]+)+";
if ($sEmail =~ /$sUserNmRegex$sDomainRegex$sEndRegex$/) {
$sRetMsg = "Email is valid";
}
else {
$sRetMsg = "Email is not valid";
}
return $sRetMsg;
}
my $sEmail = '[email protected]';
print "[Email:$sEmail] : " . Validate_Email($sEmail) . "\n";