Tuesday, February 26, 2008

JavaScript Validate Email using RegEx

Use the code below with an asp.net custom validator to check if an email is valid.
The code below check for a value if no value is provided then is not a valid email.

The pattern below will work with gmail's email address with "+" such as johnsmith+test@gmail.com



function ValidateEmail(sender, args)
{
if(args.Value.trim().length > 0)
{
var ex = /^([a-zA-Z0-9_.+-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
var re = new RegExp(ex );

if(re.exec(args.Value))
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}

}
else
{
args.IsValid = false;
}
}



Monday, February 18, 2008

Credit Card Expiration Date Validation -Javascript Function




function ValidateExpDate()

{

var ccExpYear = 20 + $F('<%= txtCCExpirationYear.ClientID%>');

var ccExpMonth = $F('<%= txtCCExpirationMonth.ClientID%>');



var expDate=new Date();

expDate.setFullYear(ccExpYear, ccExpMonth, 1);



var today = new Date();



if (expDate<today)

{

// Credit Card is expire

return false;

}

else

{

// Credit is valid

return true;

}

}



Wednesday, February 13, 2008

Compilation Error CS0433

I fixed this error by changing the Page Property CodeFile to CodeBehind on the mater page and the content pages.

Use CodeBehind when working on Web Application projects in ASP.NET 2.0