Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. <script>
  2. const form = document.getElementById('person-create-form');
  3. function getInputs(event) {
  4. event.preventDefault();
  5. const name = document.getElementById('name-input').value;
  6. const email = document.getElementById('email-input').value;
  7. const age = document.getElementById('age-input').value;
  8. const splitEmail = email.split('');
  9.  
  10. if (parseInt(age) < 18) {
  11. window.alert('You are underage.')
  12. }
  13. if(!splitEmail.includes('@')) {
  14. window.alert('Please enter a valid email address.')
  15. }
  16. if (parseInt(age) > 18 && splitEmail.includes('@')) {
  17. console.log(name);
  18. console.log(email);
  19. console.log(age);
  20. form.reset();
  21. window.alert('Info submitted!');
  22. }
  23. }
  24. form.addEventListener('submit', event => getInputs(event));
  25. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement