Link to home
Start Free TrialLog in
Avatar of lulu50
lulu50Flag for United States of America

asked on

Validating an email address

Hi,

I need your help please.

I'm trying to validate an email address

function ValidateData() {
        //debugger;
        var StartCreateDate = $('#FromCreatedDate').val();
        var EndCreateDate = $('#ToCreatedDate').val();
        var StartMigrationDate = $('#FromMigrationDate').val();
        var EndMigrationDate = $('#ToMigrationDate').val();
        var SendToEmail = $('#SendEmailTo').val();
       
        if ((StartCreateDate != null && EndCreateDate != null) && (StartCreateDate > EndCreateDate)) {
            alert("From create date must be greater than to create date")
            return false;
        }
        if ((StartMigrationDate != null && EndMigrationDate != null) && (StartMigrationDate > EndMigrationDate)) {
            alert("From migration date must be greater than to migration date")
            return false;
        }
        if (SendToEmail "doesn't have the correct format")  //Here I want to validate my email address $('#SendEmailTo').val();
        {
            alert("Email format is incorrect")
            return false;
        }

        return true;
    }

Open in new window



Thank you,
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
EXPERT CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lulu50

ASKER

Thank you guys for your help


I'm getting this error



Parser Error
  Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

 Parser Error Message: "[" is not valid at the start of a code block.  Only identifiers, keywords, comments, "(" and "{" are valid.


Source Error:



Line 110:
Line 111:    function emailHaveCorrectFormat(email) {
Line 112:        var filter = ^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$;
Line 113:        return filter.test(email.value);
Line 114:    }
Avatar of lulu50

ASKER

the same error I try the other one


Parser Error
  Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

 Parser Error Message: "[" is not valid at the start of a code block.  Only identifiers, keywords, comments, "(" and "{" are valid.


Source Error:



Line 124:        var EndMigrationDate = $('#ToMigrationDate').val();
Line 125:        var SendToEmail = $('#SendEmailTo').val();
Line 126:        var ValidEmail = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
Line 127:
Line 128:
Avatar of Bill Prew
Bill Prew

Not sure your environment, but in a couple of bare bones tests here the part I suggested seems to work...

https://jsfiddle.net/wbtzo45r/

http://tpcg.io/UPQcnK3G


»bp
I miss the slahes :

function emailHaveCorrectFormat(email) {
    var filter = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
    return filter.test(email.value);
}

Open in new window

Avatar of lulu50

ASKER

I still get the same error
it's looking for this (  )



Parser Error
  Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

 Parser Error Message: "[" is not valid at the start of a code block.  Only identifiers, keywords, comments, "(" and "{" are valid.


Source Error:



Line 110:
Line 111:function emailHaveCorrectFormat(email) {
Line 112:    var filter = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
Line 113:    return filter.test(email.value);
Line 114:}
 

 Source File:  /Views/CareAdvanceBusinessRules/Management.cshtml    Line:  112
it's an issue with your code editor not with the code itself or maybe another block of your page
Avatar of lulu50

ASKER

yes I agree Thank you so much
Avatar of lulu50

ASKER

Thank you
you welcome