Search This Blog

Wednesday, July 14, 2010

Check ValidEmail

Check ValidEmail - JavaScript
function isValidEmail(emailAddressControl)
{
var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
var emailid = emailAddressControl.value;

var matchArray = emailid.match(emailPat);

if (matchArray == null) {

alert("Invalid e-mail address");

emailAddressControl.focus();

return false;

}
return true; }
}
---------------------------------------------------------------
In your web form Page_Load, you can add the following code
--------------------------------------------------------

if (!Page.ClientScript.IsClientScriptIncludeRegistered(typeof(pgOrders), "MyScript"))

{

Page.ClientScript.RegisterClientScriptInclude(typeof(pgOrders), "MyScript", "JScript.js");

}

---------Explain------------------------------------------
typeof(pgOrders)

In this example, pgOrders is the actual type of the page in which the JavaScript is being included. This works better, because you are statically typing the reference to the page at compile time rather than dynamically determining the type of the page at runtime.
Check ValidEmail - JavaScript
function isValidEmail(emailAddressControl)
{
var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
var emailid = emailAddressControl.value;

var matchArray = emailid.match(emailPat);

if (matchArray == null) {

No comments:

Post a Comment