This is a solution to the Newsletter sign-up form with success message challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.
Note: Delete this note and update the table of contents based on what sections you keep.
Users should be able to:
- Add their email and submit the form
- See a success message with their email after successfully submitting the form
- See form validation messages if:
- The field is left empty
- The email address is not formatted correctly
- View the optimal layout for the interface depending on their device's screen size
- See hover and focus states for all interactive elements on the page
- Semantic HTML5 markup
- CSS custom properties
- Flexbox
- CSS Grid
- Mobile-first workflow
- Regex (Regular Expression)
- window.location Object
- event.preventDefault()
window.addEventListener('load', adjustImgSrc);
window.addEventListener('resize', adjustImgSrc);
submitBtn.addEventListener('click', event => {
event.preventDefault();
const inputValue = document.querySelector('input').value;
let checkEmail = inputValue.match(/\b[A-Za-z0-9._+%-]+@[A-Za-z]+\.[A-Za-z]{2,}\b/);
if(!checkEmail){
errorMsg.classList.add('is_visible');
errorMsg.parentElement.nextElementSibling.classList.add('input-error');
}
else
window.location.href = `${window.location.origin}/subscribe.html?${inputValue}`;
})
- Regex - This helped me practice and test Emaill address pattern.
- Window Location - This is an amazing article which helped me finally understand Window Location Object.
- Frontend Mentor - @yourusername
- Twitter - @yourusername