Advertisement
Guest User

Untitled

a guest
Feb 10th, 2017
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. #include <exception>
  2. #include <iostream>
  3. #include <regex>
  4.  
  5. class email
  6. {
  7. private:
  8. std::string mail;
  9. public:
  10.  
  11. email(std::string mail)
  12. {
  13. this->mail = mail;
  14. }
  15.  
  16. bool isMail()
  17. {
  18. //const std::regex pattern("[A-Z0-9._%-]+@[A-Z0-9.-]+?\\.[A-Z]{2,4}b\\.[A-Z]{2,4}");
  19. const std::regex pattern("[A-Z0-9._%-]+@[A-Z0-9.-]+\\.com.br?+\\.net.br?+\\.org.br)$");
  20. std::regex_match(mail, pattern);
  21. }
  22.  
  23. email* print()
  24. {
  25.  
  26. std::cout<<"\n\tEmail: "<<mail<<(email(mail).isMail()?" Valid":" Invalid")<<"\n";
  27.  
  28. }
  29. };
  30.  
  31. class phone
  32. {
  33. private:
  34. std::string tel;
  35.  
  36. public:
  37.  
  38. phone(std::string tel)
  39. {
  40. this->tel = tel;
  41. }
  42.  
  43. /*
  44. * ^(\\(?[0-9]{2}\\)?|[-. ]?)[-. ]?[0-9]{4}[-. ]?[0-9]{4}$
  45. * alida nos formatos:
  46. * xx xxxx xxxx, xx.xxxx.xxxx, xx-xxxx-xxxx
  47. * (xx) xxxx xxx, (xx).xxxx.xxx,(xx)-xxxx-xxx
  48. * xxxx xxxx, xxxx.xxxx, xxxx-xxxx
  49. */
  50.  
  51. bool isPhone()
  52. {
  53. const std::regex pattern("^(\\(?[0-9]{2}\\)?|[-. ]?)[-. ]?[0-9]{4}[-. ]?[0-9]{4}$");
  54. std::regex_match(tel, pattern);
  55. }
  56.  
  57. phone* print()
  58. {
  59. std::cout<<"\n\tPhone: "<<tel<<(phone(tel).isPhone()?" Valid":" Invalid")<<"\n";
  60. }
  61. };
  62.  
  63. int main(void)
  64. {
  65.  
  66. std::string email1 = "regex_cpp@net.br";
  67. std::string email2 = "regex_cpp@terra.com.br";
  68.  
  69. std::string email3 = "regex_cpp@hotmail.com.br.net"; /* nao pode validar */
  70. std::string email4 = "regex_cpp@hotmail.com";
  71.  
  72. std::string email5 = "regex_cpp@yahoo.com.br";
  73. std::string email6 = "regex_cpp@gmail.com";
  74.  
  75. std::string email7 = "regex_cpp@bol.com.br";
  76. std::string email8 = "regex.cpp@bol.com";
  77.  
  78. std::string email9 = "reg_ex.cpp@bol.com";
  79. std::string email10 = "reg_ex.cpp@org.br";
  80. std::string email11 = "reg_ex.cpp@net.org.br";
  81.  
  82. std::string phone1 = "(17) 3487-1141";
  83.  
  84. /*
  85. email *v1 = new email(email9);
  86. email *v2 = new email(email10);
  87.  
  88. std::cout <<"\n\tEmail 1: "<< email9 << (v1->isMail()? " Valid":" Invalid") <<"\n\n\tEmail 2: "<< email10 << (v2->isMail()? " Valid":" Invalid") <<"\n\n";
  89.  
  90. v1->print();
  91. v2->print();
  92. */
  93.  
  94.  
  95. email(email1).print();
  96. email(email2).print();
  97. email(email3).print();
  98. email(email4).print();
  99. email(email5).print();
  100. email(email6).print();
  101. email(email7).print();
  102. email(email8).print();
  103. email(email9).print();
  104. email(email10).print();
  105. email(email11).print();
  106.  
  107. phone(phone1).print();
  108.  
  109. // email(email9).isMail().print(); erro
  110.  
  111. //std::cout <<"\n\tEmail: "<< email10 << (email(email10).isMail()? " Valid":" Invalid")<<"\n\n";
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement