Bir metnin e-posta olup olmadağı aşağıdaki fonksiyonu kullanarak doğrulanabilir.
c#
public void SendEmail(){
if (!ValidateEmail(mailTo))
{
MessageBox.Show("Invalid To mail address");
return;
}
}
private bool ValidateEmail(string emailAddress)
{
string patternStrict = @"^(([^<>()[\]\\.,;:\s@\""]+"
+ @"(\.[^<>()[\]\\.,;:\s@\""]+)*)|(\"".+\""))@"
+ @"((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
+ @"\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+"
+ @"[a-zA-Z]{2,}))$";
System.Text.RegularExpressions.Regex reStrict = new System.Text.RegularExpressions.Regex(patternStrict);
bool isStrictMatch = reStrict.IsMatch(emailAddress);
return isStrictMatch;
}
JavaScript
<script>
function SendEmail() {
let mailTo =document.getElementById("mailTo").value;
if (!validateEmail(mailTo)) {
alert('Invalid To mail address.');
return;
}
}
function ValidateEmail(email) {
var re = /^(([^<>()\[\]\\.,;:\s@@"]+(\.[^<>()\[\]\\.,;:\s@@"]+)*)|(".+"))@@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
</script>