Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am having one Form "email.cs" in my project name as "Email Client"
In that form I am having one LinkLabel Control name as "Verify Email Address"
I designed one web Page name as "Verify.aspx".In this web page I have one TextBox Control
and one Button Control. When I enter any address into the textBox and click on the button it
immediately checks whether the email address entered into the textBox is actually present or
not on the "GMAIL-SERVER".
So my Question is that How can I Add this Web-Page into my Windows-Forms Project
You need to put some effort into this before asking on SO, try searching online and look at examples (For example here). You can just add a WebControl to the form.
You can use Regex to validate email addresses or try the following.
//NOTE: This code will not catch double periods, extra spaces. For more precision, stick to Regex.
public bool IsEmailValid(string emailAddress)
{
try
{
MailAddress m = new MailAddress(emailAddress);
return true;
}
catch (FormatException)
{
return false;
}
}
The Regex way to validate Email address:
String email = "test#gmail.com";
Regex regex = new Regex(#"^[\w!#$%&'*+\-/=?\^_`{|}~]+(\.[\w!#$%&'*+\-/=?\^_`{|}~]+)*"
+ "#"
+ #"((([\-\w]+\.)+[a-zA-Z]{2,4})|(([0-9]{1,3}\.){3}[0-9]{1,3}))$";);
Match match = regex.Match(email);
if (match.Success)
//Email is has the right format.
else
//Email doesn't have the correct format.
But if your goal is to communicate with Gmail, then you will need to make use of:
GMAIL APIs - https://developers.google.com/gmail/
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am looking for a way to take phone numbers Input from an end user, given the various ways that can be formatted, and reformat it in a more standardized way. My end users work with only US phone numbers. Looking at the C# port of google's LibPhoneNumber, I assume it was made for exactly this task, but I can't figure out its usage.
My goals for output is to standardize on 999-999-9999 format.
So if the user inputs (516)666-1234, I want to output 516-666-1234.
If the users inputs 5166661234, I want to output 516-666-1234.
If possible, if the user inputs (516)666-1234x102, I'd like the output to be 516-666-1234x102
If the library can't handle extensions, I'll deal with that problem externally.
What calls do I have to make to produce the desired output?
Alternatively, can you provide a link that provides the answer to my question?
You have to combine RegEx (to string out non-numeric fields) and string formatting. Note that string.Format of a number is tricky, so we format the 10-digit phone number and then append the extension.
public string getPhoneNumber(string phone) {
string result = System.Text.RegularExpressions.Regex.Replace(phone, #"[^0-9]+", string.Empty);
if (result.Length <= 10) {
return Double.Parse(result).ToString("###-###-####");
} else {
return Double.Parse(result.Substring(0,10)).ToString("###-###-####") +
"x " + result.Substring(10, result.Length-10);
}
}
To do this right, I'd want to check for "1" at the start of my digits and ditch it. I'd want to check for < 10 characters and make some assumptions about area code, etc.
But - this is a good start.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am sorry for that bad Title, but basicaly my problem is really simple. I got 1 string which is basic alphabet and the second string which is gonna be part of the alphabet (8 characters) which user will fill up by himself. If 2 characters are the same, they will get removed and then rest of characters will be in the TextBox3. could someone pls help me ?
string alphabet = "abcdefghijklmnopqrstuvwxyz_*";
string special = TextBox2.Text;
I assume you want to check the existence of substring and remove from the parent string, Try this
string alphabet = "abcdefghijklmnopqrstuvwxyz_*";
string special = textBox2.Text;
if (alphabet.ToLowerInvariant().Contains(special))
{
textBox3.Text = alphabet.Replace(special, "");
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
In my "ServiceEditModel" class i have a property Url with typeof Uri. For validation I search a Regex that check if the Url, which is filled up on my "Edit" page, is valid.
The Regex should check
Is there a http:// or https://
That the body only contains alphabetic characters and numbers
And the ending is like for example .com, .net, .ch
It should be possible, that there is another parameter behind the ending like for example https://stackoverflow.com/questions
My Code where the Regex comes in look like this:
[Required(ErrorMessageResourceType = typeof(Resources.ApplicationTemplate), ErrorMessageResourceName = "UrlRequired")]
[RegularExpression("REGEX COMES HERE", ErrorMessageResourceType = typeof(Resources.ApplicationTemplate), ErrorMessageResourceName = "InvalidUrl")]
public Uri Url { get; set; }
I already looked for Regex but can't find the right one because this is actually my first experiance with Regex.
Thanks for Help!
EDIT
I updated my regex so that it also allows url's with a "-" character such as http://www.comsoft-direct.ch/
Updated regex: ^(http|https):\/\/([\w\d + (\-)+?]+\.)+[\w]+(\/.*)?$
This Regex should check simple scenarios according to your constraints. You can easily play with it and improve it (which I strongly recommend, firstly because it's very simple at this state and secondly because you are a Regex beginner :)).
^(http|https):\/\/[\w\d]+\.[\w]+(\/[\w\d]+)$
Check it on Regex 101
Basic explanation:
(http|https):\/\/
Should start with http or https, followed by ://
[\w\d]+
Followed by N letters and/or digits
\.[\w]+
Followed by a dot and a set of letters. e.g.: .com, .net and such (note that you must change to \.[\d\w]+ to allow digits also)
(\/[\w\d]+)
Followed, optionally, by a / and a set of letters and/or digits (e.g.: /questions)
NOTE: If you want a full-generic url validator, you must then google for that.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have a string with a web address in it which may or may not include the protocol at the beginning. This is going into the href of a html a tag so needs to include the protocol to avoid the address being treated as a relative address. What's the shortest code to achieve this. Just to be clear, the possible inputs and expected outputs are below.
string url = "www.google.com"; //expected "http://www.google.com"
string url = "google.com"; //expected "http://google.com"
string url = "http://www.google.com"; //expected "http://www.google.com"
string url = "https://www.google.com"; //expected "https://www.google.com"
Update:
To those that want to know what I already tried, it was a couple of if statements checking if the url already started with one of the relevant prefixes and then appending it on if necessary. This is trivial for any c# programmer but doesn't come close to the "shortest way". It worked without any problems but my question is to see what better ways there are of doing it.
You can use UriBuilder class for this.
public static Uri GetUri(this string s)
{
return new UriBuilder(s).Uri;
}
This constructor initializes a new instance of the UriBuilder class with the Fragment, Host, Path, Port, Query, Scheme, and Uri properties set as specified in uri.
If uri does not specify a scheme, the scheme defaults to "http:".
This is going into the href of a html a tag so needs to include the protocol to avoid the address being treated as a relative address
You can simply use // to let the browser know it's an absolute url and not a relative path, the browser will then use http or https appropriately (based on the current page context).
For example:
//www.google.com/
Assuming only http/https protocols are expected:
if (!url.StartsWith("https://", StringComparison.OrdinalIgnoreCase)
&& !url.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
url = "http://" + url;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to build a searching function with keywords format on Entity Framework.
void funcSearch(string keywork)
{
if (keywork == "[tag]")
{
//regex for is tag
//do search tag
}
if (keywork == "user:1234")
{
//regex for userid is 1234
//do search user with 1234
}
...
}
Can i use regex to parse a query string format like SO, or any method? a function to to be able to analyze all of the cases with corresponding keyword?
tags [tag]
exact "words here"
author user:1234
user:me (yours)
score score:3 (3+)
score:0 (none)
answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
views views:250
sections title:apples
body:"apples oranges"
url url:"*.example.com"
favorites infavorites:mine
infavorites:1234
status closed:yes
duplicate:no
migrated:no
wiki:no
types is:question
is:answer
thank you for advice.
Yes, you can. You'd have to create a list of regular expressions to check and loop through them until you find a match. (Make sure to prioritize them correctly.)
For example, to find out if a search query is querying tags, you can use the following regex:
string query = "[tag]";
bool isTag = Regex.IsMatch(query, #"^\[.+?\]$");
Here's another regex matching a user ID:
string query = "user:1234";
var match = Regex.Match(query, #"^user:(\d+)$", RegexOptions.IgnoreCase);
Note that you should trim your query first.