Check if a string is a valid email via regex - Node.js Regular expression

Node.js examples for Regular expression:Match

Description

Check if a string is a valid email via regex

Demo Code


  isEmail : function(s) {
    return this.test(s, '^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$');
  },// w w w.jav  a  2s.com

  test : function(s, p) {
    s = s.nodeType == 1 ? s.value : s;

    return s == '' || new RegExp(p).test(s);
  }

Related Tutorials