You're building a form validation script in JavaScript. How would you ensure that an email input field contains a valid email address before submitting the form?

  • Using Regular Expressions: /^[^s@]+@[^s@]+.[^s@]+$/
  • Checking for '@' and '.' occurrences
  • Using a predefined list of valid email addresses
  • Using validateEmail() function
To ensure that an email input field contains a valid email address in JavaScript, you can use regular expressions. The provided regex (/^[^s@]+@[^s@]+.[^s@]+$/) validates the basic structure of an email address. The correct option offers a robust and standard approach.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *