Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
How to check email input from HTML button in Javascript

The outcome I want:

  1. Click the button (div class button)
  2. Check what is inputted (div class email)
  3. If it isn't an email, return an error that it isn't an email.
<div class="Email">
<input type="text" name="" class="em" placeholder="Email Address">
</div>
<div class="button" > <h2 class="re"> Request Access </h2> </div>
</div> 

I don't know where to start from JavaScript code. Any tips will help.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use regex to validate things like emails, passwords, usernames, etc. It's really powerful and can do a ton.

Solution:

<form class="email">
    <input type="email" class="emailInput" placeholder="Email Address" />
    <button type="submit">Request Access</button>
    <p id="error" style="color: red; display: none">Please enter a valid email</p>
</form>

<script>
    const email = document.querySelector('.emailInput');
    const submit = document.querySelector('button');
    const error = document.querySelector('#error');

    const showError = () => {
        error.style.display = 'block';
    };

    submit.addEventListener('click', (e) => {
        e.preventDefault();
        if (!email.value.match(/[^@ \t\r\n]+@[^@ \t\r\n]+\.[^@ \t\r\n]+/)) {
            return showError();
        }

        console.log('success');
    });
</script>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!