Avatar of lulu50
lulu50
Flag 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,
JavaScriptjQueryAJAXJSON

Avatar of undefined
Last Comment
leakim971

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
leakim971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
EXPERT CERTIFIED SOLUTION
Bill Prew

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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:    }
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:
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 started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
leakim971

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

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
leakim971

it's an issue with your code editor not with the code itself or maybe another block of your page
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
lulu50

ASKER
yes I agree Thank you so much
lulu50

ASKER
Thank you
leakim971

you welcome
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck