View Full Version : بررسی URL
amirepsilon
دوشنبه 08 تیر 1388, 12:42 عصر
سلام
دوستان من تابعی میخوام که بررسی که اگر رشته ای که بهش میدیم مانند URL سایت هست مقدار True بده واگر نیست False
مثلا برای این درست :
http://barnamenevis.org/forum/newthread.php?
و برای این غلط
C:\Documents and Settings
ممنون
Sajjad.Aghapour
دوشنبه 08 تیر 1388, 13:44 عصر
می تونید از Regex استفده کنید.اگه در مورد Regular Expression هم نمی دونید می تونید توی همین بخش یا بخش مقالات یه چیزایی در موردش پیدا کنی.
من زیاد از pattern ها چیزی نمی دونم ولی یه مثال ساده می تونه این باشه
Regex regex = new Regex(@"^(http://)+([A-Za-z0-9]+)\.([a-z]{2,})");
bool b = regex.IsMatch("http://GoogleA5.com");
alirezavafi
دوشنبه 08 تیر 1388, 13:57 عصر
public bool ValidateURL(string strToValidate)
{
System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"(http|https)://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?");
System.Text.RegularExpressions.Match m = r.Match(strToValidate);
return m.Success;
}
alirezavafi
دوشنبه 08 تیر 1388, 13:58 عصر
public bool ValidateURL(string strToValidate)
{
System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"(http|https)://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?");
System.Text.RegularExpressions.Match m = r.Match(strToValidate);
return m.Success;
}
sinashahab
دوشنبه 08 تیر 1388, 21:51 عصر
string t = textBox1.Text.ToLower();
if (t.StartsWith("http://"))
{
Text = "s";
}
در این کد اگر http هم کوچک و بزرگ بنویسند کار می کنه .
vBulletin® v4.2.5, Copyright ©2000-1403, Jelsoft Enterprises Ltd.