0

Let's say I use type:"email", can I get a true or false? since input type already have their own validation.

I want to use it in a javascript and if i can just do this (this is just an example code)

const email = document.getElementById('email').value;
if(email == true){
  window.alert(true);
};

if user put the correct email, then it will pops an alert.

dumdum
  • 1
  • 1

1 Answers1

0

Use HTMLInputElement#checkValidity():

const email = document.getElementById('input');

function test() {
  if (email.checkValidity()) {
    window.alert(email.value);
  };
}
<input type="email" id="input"><button onclick="test()">Verify</button>
Spectric
  • 30,714
  • 6
  • 20
  • 43