Skip to main content
Keeping it with the HTML5 form validation API
Source Link
Boldewyn
  • 82.3k
  • 45
  • 159
  • 214

In modern browsers you can build on top of @Sushil's answer with pure JavaScript and the DOM:

function validateEmail(value) {
  if (!value || value.length == 0){
     return false;
  }
  var input = document.createElement('input');

  input.type = 'email';
  input.required = true;
  input.value = value;
    
  return typeof input.checkValidity ===== 'function' ? input.checkValidity() : /\S+@\S+\.\S+/.test(value);
}

I've put together an example in the fiddle http://jsfiddle.net/boldewyn/2b6d5/. Combined with feature detection and the bare-bones validation from Squirtle's Answer, it frees you from the regular expression massacre and does not bork on old browsers.

In modern browsers you can build on top of @Sushil's answer with pure JavaScript and the DOM:

function validateEmail(value) {
  if (!value || value.length == 0){
     return false;
  }
  var input = document.createElement('input');

  input.type = 'email';
  input.value = value;
    
  return typeof input.checkValidity == 'function' ? input.checkValidity() : /\S+@\S+\.\S+/.test(value);
}

I've put together an example in the fiddle http://jsfiddle.net/boldewyn/2b6d5/. Combined with feature detection and the bare-bones validation from Squirtle's Answer, it frees you from the regular expression massacre and does not bork on old browsers.

In modern browsers you can build on top of @Sushil's answer with pure JavaScript and the DOM:

function validateEmail(value) {
  var input = document.createElement('input');

  input.type = 'email';
  input.required = true;
  input.value = value;
    
  return typeof input.checkValidity === 'function' ? input.checkValidity() : /\S+@\S+\.\S+/.test(value);
}

I've put together an example in the fiddle http://jsfiddle.net/boldewyn/2b6d5/. Combined with feature detection and the bare-bones validation from Squirtle's Answer, it frees you from the regular expression massacre and does not bork on old browsers.

Add null and empty string check.
Source Link
Kevin Fichter
  • 1.1k
  • 1
  • 11
  • 17

In modern browsers you can build on top of @Sushil's answer with pure JavaScript and the DOM:

function validateEmail(value) {
  if (!value || value.length == 0){
     return false;
  }
  var input = document.createElement('input');

  input.type = 'email';
  input.value = value;
    
  return typeof input.checkValidity == 'function' ? input.checkValidity() : /\S+@\S+\.\S+/.test(value);
}

I've put together an example in the fiddle http://jsfiddle.net/boldewyn/2b6d5/. Combined with feature detection and the bare-bones validation from Squirtle's Answer, it frees you from the regular expression massacre and does not bork on old browsers.

In modern browsers you can build on top of @Sushil's answer with pure JavaScript and the DOM:

function validateEmail(value) {
  var input = document.createElement('input');

  input.type = 'email';
  input.value = value;
    
  return typeof input.checkValidity == 'function' ? input.checkValidity() : /\S+@\S+\.\S+/.test(value);
}

I've put together an example in the fiddle http://jsfiddle.net/boldewyn/2b6d5/. Combined with feature detection and the bare-bones validation from Squirtle's Answer, it frees you from the regular expression massacre and does not bork on old browsers.

In modern browsers you can build on top of @Sushil's answer with pure JavaScript and the DOM:

function validateEmail(value) {
  if (!value || value.length == 0){
     return false;
  }
  var input = document.createElement('input');

  input.type = 'email';
  input.value = value;
    
  return typeof input.checkValidity == 'function' ? input.checkValidity() : /\S+@\S+\.\S+/.test(value);
}

I've put together an example in the fiddle http://jsfiddle.net/boldewyn/2b6d5/. Combined with feature detection and the bare-bones validation from Squirtle's Answer, it frees you from the regular expression massacre and does not bork on old browsers.

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

In modern browsers you can build on top of @Sushil's answer with pure JavaScript and the DOM:

function validateEmail(value) {
  var input = document.createElement('input');

  input.type = 'email';
  input.value = value;
    
  return typeof input.checkValidity == 'function' ? input.checkValidity() : /\S+@\S+\.\S+/.test(value);
}

I've put together an example in the fiddle http://jsfiddle.net/boldewyn/2b6d5/. Combined with feature detection and the bare-bones validation from Squirtle's AnswerSquirtle's Answer, it frees you from the regular expression massacre and does not bork on old browsers.

In modern browsers you can build on top of @Sushil's answer with pure JavaScript and the DOM:

function validateEmail(value) {
  var input = document.createElement('input');

  input.type = 'email';
  input.value = value;
    
  return typeof input.checkValidity == 'function' ? input.checkValidity() : /\S+@\S+\.\S+/.test(value);
}

I've put together an example in the fiddle http://jsfiddle.net/boldewyn/2b6d5/. Combined with feature detection and the bare-bones validation from Squirtle's Answer, it frees you from the regular expression massacre and does not bork on old browsers.

In modern browsers you can build on top of @Sushil's answer with pure JavaScript and the DOM:

function validateEmail(value) {
  var input = document.createElement('input');

  input.type = 'email';
  input.value = value;
    
  return typeof input.checkValidity == 'function' ? input.checkValidity() : /\S+@\S+\.\S+/.test(value);
}

I've put together an example in the fiddle http://jsfiddle.net/boldewyn/2b6d5/. Combined with feature detection and the bare-bones validation from Squirtle's Answer, it frees you from the regular expression massacre and does not bork on old browsers.

Baked feature detection and basic graceful degradation in
Source Link
Ronny
  • 4.5k
  • 2
  • 25
  • 32
Loading
Copy edited. Added some context.
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 109
  • 132
Loading
Post Made Community Wiki by pera
Source Link
Boldewyn
  • 82.3k
  • 45
  • 159
  • 214
Loading