Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- const form = document.getElementById('person-create-form');
- function getInputs(event) {
- event.preventDefault();
- const name = document.getElementById('name-input').value;
- const email = document.getElementById('email-input').value;
- const age = document.getElementById('age-input').value;
- const splitEmail = email.split('');
- if (parseInt(age) < 18) {
- window.alert('You are underage.')
- }
- if(!splitEmail.includes('@')) {
- window.alert('Please enter a valid email address.')
- }
- if (parseInt(age) > 18 && splitEmail.includes('@')) {
- console.log(name);
- console.log(email);
- console.log(age);
- form.reset();
- window.alert('Info submitted!');
- }
- }
- form.addEventListener('submit', event => getInputs(event));
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement