Advertisement
Guest User

Untitled

a guest
May 27th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. const Validator = class {
  2. min(content, min) {
  3. if(content === undefined || content == null) return false
  4. return content.length >= min
  5. }
  6.  
  7. max(content, max) {
  8. if(content === undefined || content == null) return false
  9. return content.length <= max
  10. }
  11.  
  12. email(content) {
  13. if(content === undefined) return false
  14. var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  15. return re.test(String(content).toLowerCase());
  16. }
  17.  
  18. phone(content) {
  19. if(content === undefined) return false
  20. var re = /^[0-9]{11}$/
  21. return re.test(String(content))
  22. }
  23.  
  24. zipcode(content) {
  25. if(content === undefined) return false
  26. var re = /^[0-9]{2}-[0-9]{3}$/
  27. return re.test(String(content));
  28. }
  29.  
  30. date(content) {
  31. if(content === undefined || content === null) return false
  32. return true
  33. }
  34.  
  35. pin(content) {
  36. let pin = [
  37. 988745, 760673, 363838, 470007, 803040, 992605,
  38. 406271, 369719, 351539, 982549, 176947, 249669,
  39. 439939, 912752, 389829, 815523, 170655, 837044,
  40. 419885, 522623, 483999, 209081, 725707, 527000,
  41. 364304, 631566, 542315, 482296, 742676, 342553,
  42. 340725, 708021, 915772, 106195, 141340, 598094,
  43. 212395, 983458, 828614, 806511
  44. ]
  45. if(pin.indexOf(parseInt(content)) === -1) return false
  46. return true
  47. }
  48. }
  49.  
  50. const Errors = class {
  51. min(min) {
  52. return "To pole wymaga minimum " + min + " znaków"
  53. }
  54.  
  55. max(max) {
  56. return "To pole może mieć maksymalnie " + max + " znaków"
  57. }
  58.  
  59. email() {
  60. return "Niepoprawny adres email"
  61. }
  62.  
  63. phone() {
  64. return "Niepoprawny numer telefonu"
  65. }
  66.  
  67. zipcode() {
  68. return "Niepoprawny kod pocztowy"
  69. }
  70.  
  71. date() {
  72. return "Niepoprawna data"
  73. }
  74.  
  75. pin() {
  76. return "Niepoprawny numer pin"
  77. }
  78. }
  79.  
  80. export {
  81. Validator,
  82. Errors,
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement