Wednesday, November 13, 2013

Javascript Collection

Best Practices:  JavaScript should be at declared right before the closing body tag.
If script uses document.write to insert part of the page's content, it can't be moved lower in the page.
========================
onsubmit="return !!(ValidateEmail(document.PREMIUM_FORM.email) & ValidatePhone(document.PREMIUM_FORM.phone) )"
========================
function ValidateName(inputtxt)
{
    if(inputtxt.value=="")
    {
        alert("Please Enter Your Name");
        return false;
    }
    return true
}
========================
function ValidatePhone(inputtxt)
{
var phoneno = /^\d{10}$/;  

  var phoneno = /^\d{10}$/;
  if(inputtxt.value.match(phoneno))
     {
       return true;
     }
   else
     {
       alert("Please provide a valid Phone Number");
       return false;
     }
}
========================
function ValidateEmail(email)
{
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(email.value)) {
        alert("Please provide a valid email address");
    return false;
    }
    return true
}
========================
Example:
sample-javascript-registration
========================

No comments:

Post a Comment