473,395 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to perform data validation for emails with C++?

I have this big project and I need to do data validation for an email. I have googled several stuff but I always get something so not in the topic.
May 15 '13 #1
2 3016
johny10151981
1,059 1GB
try this link
May 15 '13 #2
Sherin
77 64KB
Try This Code

Expand|Select|Wrap|Line Numbers
  1. #include <bits/stdc++.h> 
  2. using namespace std; 
  3.  
  4. bool isChar(char c) 
  5.     return ((c >= 'a' && c <= 'z') 
  6.             || (c >= 'A' && c <= 'Z')); 
  7.  
  8. bool isDigit(const char c) 
  9.     return (c >= '0' && c <= '9'); 
  10.  
  11. bool is_valid(string email) 
  12.  
  13.     if (!isChar(email[0])) { 
  14.  
  15.         return 0; 
  16.     } 
  17.  
  18.     int At = -1, Dot = -1; 
  19.  
  20.     for (int i = 0; 
  21.         i < email.length(); i++) { 
  22.  
  23.  
  24.         if (email[i] == '@') { 
  25.  
  26.             At = i; 
  27.         } 
  28.  
  29.         else if (email[i] == '.') { 
  30.  
  31.             Dot = i; 
  32.         } 
  33.     } 
  34.  
  35.     if (At == -1 || Dot == -1) 
  36.         return 0; 
  37.  
  38.     if (At > Dot) 
  39.         return 0; 
  40.  
  41.     return !(Dot >= (email.length() - 1)); 
  42.  
  43. int main() 
  44.     string email = "contribute@geeksforgeeks.org"; 
  45.  
  46.     bool ans = is_valid(email); 
  47.  
  48.     if (ans) { 
  49.         cout << email << " : "
  50.             << "valid" << endl; 
  51.     } 
  52.     else { 
  53.         cout << email << " : "
  54.             << "invalid" << endl; 
  55.     } 
  56.  
  57.     return 0; 
  58.  
Dec 29 '20 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sonia | last post by:
Has anybody done UI data validation usinf XML Schemas. Any pointers will help. Thanks!
2
by: Gustaf Liljegren | last post by:
Here's a very general programming question. I often wonder where to put the data validation when adding data to a struct or class, using its constructor. Suppose for example I got a class called...
1
by: Bill nguyen | last post by:
I use the sub below to detect data entry error. The problem is that users are still able to move out of the textbox AFTER the sub is run (and error msg popped up) without having to correct the...
4
by: kids_pro | last post by:
What is the different between Business rule & data validation? How much impact does it give in OOP concept? Thanks, Kid
0
by: ss | last post by:
Hi, I would like to know like what is the best method of writing validation code in the n-tier application. For example in Business Logic Layer How do I write Data Validation Code, what are all...
4
by: sanou | last post by:
Hi No doubt this question, or a similar version of it, has been asked before. But, I was looking around the forums and i couldn't find anything. I'm using VC++ to create a simple calculator...
3
by: MBReikowsky | last post by:
Ok this is homework, and I have wrestled with this for quite awhile now. My program is supposed to give an error message if the user enters any invalid entries. The program works great when the user...
2
by: =?Utf-8?B?dGFtZWU=?= | last post by:
I have a data list of over 1,000 spare parts. I set it up with a master data list in a separate workbook and data validation works fine. I need autocomplete so I tried inserting a combo box with...
2
by: KDawg44 | last post by:
I am validating some html form input data with some javascript. How do I prevent the form from performing the ACTION if the data validation fails? Thanks.
4
by: banderson | last post by:
Hello Bytes/Scripts folks! I am trying to implement validation for a combination of two fields in a table (through a form). I have a form “frmAddAddr2” that is bound to the table “tblLKUPAddr2”....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.