Skip to main content
Copy edited.
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 109
  • 132

My knowledge of regexregular expressions is not that good. That's why I check the general syntax with a simple regexregular expression first, and check more specific options with other functions afterwards. This may not be not the best technical solution, but this way I'm way more flexible and faster.

The most common errors I've come across are spaces (especially at the beginngingbeginning and end) and occasionally a double dot.

function check_email(val){
    if(!val.match(/\S+@\S+\.\S+/)){ // Jaymon's / Squirtle's solution
        // doDo something
        return false;
    }
    if( val.indexOf(' ')!=-1 || val.indexOf('..')!=-1){
        // doDo something
        return false;
    }
    return true;
}

check_email('check@thiscom'); // returnsReturns false
check_email('[email protected]'); // returnsReturns false
check_email(' [email protected]'); // returnsReturns false
check_email('[email protected]'); // returnsReturns true

My knowledge of regex is not that good. That's why I check the general syntax with a simple regex first, and check more specific options with other functions afterwards. This may not be not the best technical solution, but this way I'm way more flexible and faster.

The most common errors I've come across are spaces (especially at the beginnging and end) and occasionally a double dot.

function check_email(val){
    if(!val.match(/\S+@\S+\.\S+/)){ // Jaymon's / Squirtle's solution
      // do something
      return false;
    }
    if( val.indexOf(' ')!=-1 || val.indexOf('..')!=-1){
      // do something
      return false;
    }
    return true;
}

check_email('check@thiscom'); // returns false
check_email('[email protected]'); // returns false
check_email(' [email protected]'); // returns false
check_email('[email protected]'); // returns true

My knowledge of regular expressions is not that good. That's why I check the general syntax with a simple regular expression first and check more specific options with other functions afterwards. This may not be not the best technical solution, but this way I'm way more flexible and faster.

The most common errors I've come across are spaces (especially at the beginning and end) and occasionally a double dot.

function check_email(val){
    if(!val.match(/\S+@\S+\.\S+/)){ // Jaymon's / Squirtle's solution
        // Do something
        return false;
    }
    if( val.indexOf(' ')!=-1 || val.indexOf('..')!=-1){
        // Do something
        return false;
    }
    return true;
}

check_email('check@thiscom'); // Returns false
check_email('[email protected]'); // Returns false
check_email(' [email protected]'); // Returns false
check_email('[email protected]'); // Returns true
Post Made Community Wiki by pera
I added a 'true' in the function and added more examples
Source Link
Linkmichiel
  • 2.1k
  • 4
  • 23
  • 27

My knowledge of regex is not that good. That's why I check the general syntax with a simple regex first, and check more specific options with other functions afterwards. This may not be not the best technical solution, but this way I'm way more flexible and faster.

The most common errors I've come across are spaces (especially at the beginnging and end) and occasionally a double dot.

function check_email(val){
    if(!val.match(/\S+@\S+\.\S+/)){ // Jaymon's / Squirtle's solution
      // do something
      return false;
    }
    if( val.indexOf(' ')!=-1 || val.indexOf('..')!=-1){
      // do something
      return false;
    }
    return true;
}

check_email('check@thiscom'); // returns false
check_email('[email protected]'); // returns false
check_email(' [email protected]'); // returns false
check_email('[email protected]'); // returns true

My knowledge of regex is not that good. That's why I check the general syntax with a simple regex first, and check more specific options with other functions afterwards. This may not be not the best technical solution, but this way I'm way more flexible and faster.

The most common errors I've come across are spaces (especially at the beginnging and end) and occasionally a double dot.

function check_email(val){
    if(!val.match(/\S+@\S+\.\S+/)){ // Jaymon's / Squirtle's solution
      // do something
      return false;
    }
    if( val.indexOf(' ')!=-1 || val.indexOf('..')!=-1){
      // do something
      return false;
    }
}

check_email('[email protected]'); // returns false

My knowledge of regex is not that good. That's why I check the general syntax with a simple regex first, and check more specific options with other functions afterwards. This may not be not the best technical solution, but this way I'm way more flexible and faster.

The most common errors I've come across are spaces (especially at the beginnging and end) and occasionally a double dot.

function check_email(val){
    if(!val.match(/\S+@\S+\.\S+/)){ // Jaymon's / Squirtle's solution
      // do something
      return false;
    }
    if( val.indexOf(' ')!=-1 || val.indexOf('..')!=-1){
      // do something
      return false;
    }
    return true;
}

check_email('check@thiscom'); // returns false
check_email('[email protected]'); // returns false
check_email(' [email protected]'); // returns false
check_email('[email protected]'); // returns true
Source Link
Linkmichiel
  • 2.1k
  • 4
  • 23
  • 27

My knowledge of regex is not that good. That's why I check the general syntax with a simple regex first, and check more specific options with other functions afterwards. This may not be not the best technical solution, but this way I'm way more flexible and faster.

The most common errors I've come across are spaces (especially at the beginnging and end) and occasionally a double dot.

function check_email(val){
    if(!val.match(/\S+@\S+\.\S+/)){ // Jaymon's / Squirtle's solution
      // do something
      return false;
    }
    if( val.indexOf(' ')!=-1 || val.indexOf('..')!=-1){
      // do something
      return false;
    }
}

check_email('[email protected]'); // returns false