Bug report on Timbu.com

This is my timbu.com bug report in compliance with the requirement for moving to the second stage of the 5th edition of the Hotels.ng Internship program.

The bug: No validation of input of email subscription form

The bug I’m reporting is on the visa page here https://timbu.com/visa.

Email subscription form at https://timbu.com/visa

This form doesn’t look any different from the one on the homepage which works fine, but this doesn’t. The input of the form is not validated before submission. If the form is given an invalid email address like a single character, it goes on to display a success message.

I tried with a single character email
…and boom! Everything worked fine!

How to fix the bug

Inspecting the form element shows that the ‘required’ attribute of the email field was set. Somehow, the default validation of the HTML email field is not working. This means there should be a javascript function that validates the email before it is being submitted.

The ‘validateEmail’ function which I got from stack overflow would work in this case.

function validateEmail(email) {
    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,}))$/;
    return re.test(String(email).toLowerCase());