View Full Version : مبتدی: شرط ایمیل بودن مقدار داخل TextBox
MYSASOFT110
یک شنبه 21 تیر 1394, 08:54 صبح
سلام
من میخواستم یک شرط بذارم که نوشته ایی که داخل یک تکست باکس وارد میشه،یک ایمیل باشه!مثلا اگر کاربری توی تکست باکس وارد کرد:
"mohammad"
یک پیغام خطا بده
و اگر کاربر تو تکست باکس واردکرد،مثلا:
"mohammad@gmail.com"
پیغامی نده...
ممنون میشم پاسخ بدین.
محمد رضا فاتحی
یک شنبه 21 تیر 1394, 09:15 صبح
سلام دوست عزیز
using System;
using System.Globalization;
using System.Text.RegularExpressions;
public class RegexUtilities
{
bool invalid = false;
public bool IsValidEmail(string strIn)
{
invalid = false;
if (String.IsNullOrEmpty(strIn))
return false;
// Use IdnMapping class to convert Unicode domain names.
strIn = Regex.Replace(strIn, @"(@)(.+)$", this.DomainMapper);
if (invalid)
return false;
// Return true if strIn is in valid e-mail format.
return Regex.IsMatch(strIn,
@"^(?("")(""[^""]+?""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
@"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9]{2,17}))$",
RegexOptions.IgnoreCase);
}
private string DomainMapper(Match match)
{
// IdnMapping class with default property values.
IdnMapping idn = new IdnMapping();
string domainName = match.Groups[2].Value;
try {
domainName = idn.GetAscii(domainName);
}
catch (ArgumentException) {
invalid = true;
}
return match.Groups[1].Value + domainName;
}
}
Hadi-Hashemi
یک شنبه 21 تیر 1394, 14:33 عصر
public bool IsValid(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,}))$";
Regex reStrict = new Regex(patternStrict);
return reStrict.IsMatch(emailAddress);
}
vBulletin® v4.2.5, Copyright ©2000-1403, Jelsoft Enterprises Ltd.