Monday 10 December 2012

JavaScript function to Validate Email


function validateEmail(address){
var flag=true;
if(address==""){
//** field is blank
flag=false;
} else{
var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
var emaildomain=new Array("com","net","org","edu","in","mil","gov","arpa","biz","aero","name","coop","info","pro","museum");
var suffix =address.substring(address.lastIndexOf('.')+1);
if(emaildomain.indexOf(suffix) != -1){
flag=true;
} else{ flag=false; }

if(objRegExp.test(address) == false) {
flag=false;
}
if (address.indexOf('@.',0) != -1) {
flag=false;
}
if (address.indexOf('.@',0) != -1) {
flag=false;
}
if (address.indexOf('..',0) != -1) {
flag=false;
}
}
return flag;
}   

Tuesday 4 December 2012

Differences between PHP4 and PHP5

Here's a quick overview of what has changed between PH4 and PHP5. PHP5 for the most part is backwards compatible with PHP4, but there are a couple key changes that might break your PHP4 script in a PHP5 environment.

Passed by Reference

This is an important change. In PHP4, everything was passed by value, including objects. This has changed in PHP5 -- all objects are now passed by reference.

Class Constants and Static Methods/Properties

You can now create class constants that act much the same was as define()'ed constants, but are contained within a class definition and accessed with the :: operator.
Static methods and properties are also available. When you declare a class member as static, then it makes that member accessible (through the :: operator) without an instance. (Note this means within methods, the $this variable is not available)In PHP5, all constructors are named __construct(). That is, the word construct prefixed by two underscores. Other then this name change, a constructor works the same way.
Also, the newly added __destruct() (destruct prefixed by two underscores) allows you to write code that will be executed when the object is destroyed.
PHP5 introduces interfaces to help you design common APIs. An interface defines the methods a class must implement. Note that all the methods defined in an interface must be public. An interface is not designed as a blueprint for classes, but just a way to standardize a common API.
The one big advantage to using interfaces is that a class can implement any number of them. You can still only extend on parent class, but you can implement an unlimited number of interfaces.
The one big advantage to using interfaces is that a class can implement any number of them. You can still only extend on parent class, but you can implement an unlimited number of interfaces.
There is a new error level defined as E_STRICT (value 2048). It is not included in E_ALL, if you wish to use this new level you must specify it explicitly. E_STRICT will notify you when you use depreciated code. I suggest you enable this level so you can always stay on top of things.

Visibility

Class methods and properties now have visibility. PHP has 3 levels of visibility:

Public is the most visible, making methods accessible to everyone and properties readable and writable by everyone.

Protected makes members accessible to the class itself and any subclasses as well as any parent classes.

Private makes members only available to the class itself.

Unified Constructors and Destructor

PHP5 introduces a new unified constructor/destructor names. In PHP4, a constructor was simply a method that had the same name as the class itself. This caused some headaches since if you changed the name of the class, you would have to go through and change every occurrence of that name.

Abstract Classes

PHP5 lets you declare a class as abstract. An abstract class cannot itself be instantiated, it is purely used to define a model where other classes extend. You must declare a class abstract if it contains any abstract methods. Any methods marked as abstract must be defined within any classes that extend the class. Note that you can also include full method definitions within an abstract class along with any abstract methods.

Interfaces

PHP5 introduces interfaces to help you design common APIs. An interface defines the methods a class must implement. Note that all the methods defined in an interface must be public. An interface is not designed as a blueprint for classes, but just a way to standardize a common API.

E_STRICT Error Level

There is a new error level defined as E_STRICT (value 2048). It is not included in E_ALL, if you wish to use this new level you must specify it explicitly. E_STRICT will notify you when you use depreciated code. I suggest you enable this level so you can always stay on top of things.