Click here to Skip to main content
15,889,865 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Button CLick Event:
C#
private void button1_Click(object sender, EventArgs e)
       {
           string objrb = string.Empty;
           objrb = richTextBox1.Text;
           string Msg = string.Empty;
           DateTime now = DateTime.Now;
           objService.CHAT_SEND_MESSAGE(Sender_ID, receiver_id, objrb, now, out Msg);
           Chat = richTextBox2.Text;
           if (Chat != string.Empty)
           {
               richTextBox2.Text = Chat + Tutor_Name + " : " + objrb + Environment.NewLine; ;
           }
           richTextBox1.Text = string.Empty;
       }

Solution Need:
how to check whether the string which is typed in richtextbox1 containing email id and mobile number and to display a message box and to count the number of attempts the same user trying?
Posted
Comments
Rockstar_ 5-Jun-13 3:18am    
User will enter only email ID or phone number or both?
riodejenris14 5-Jun-13 3:20am    
both rockstar!!! in richtextbox before sending to DB i have to check and send.
Prasad Khandekar 5-Jun-13 4:32am    
Hello Muhammed,

How a user is expected to enter this information in richtextbox

1. email;mobile
2. mobile;email
3. emailCrLfmobile
4. mobileCrLfemail

Also what would be the format for mobile number is it going to be internal format (Country Code + Network Prefix + Mobile Number)?

Regards,

1 solution

C#
var email = "your@email.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)
    Console.Write("correct");


for phone number use the pattern:
C#
string pattern = @"
^                  # From Beginning of line
(?:\(?)            # Match but don't capture optional (
(?<areacode>\d{3}) # 3 digit area code
(?:[\).]?)         # Optional ) or .
(?<prefix>\d{3})   # Prefix
(?:[-\.]?)         # optional - or .
(?<suffix>\d{4})   # Suffix
(?!\d)             # Fail if eleventh number found";
</suffix></prefix></areacode>

Source[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900