Tag Archives: Javascript

Check email address format (PHP & Javascript)

Here are two code snippets to verify email addresses, which is quite useful when you wish to validate a form with Javascript or PHP, avoiding users to write anything as email.

Verify email format with Javascript

Insert this code between <head> and </head> tags of your HTML document :



Insert a form between <body> and </body> tags :



Eventonsubmit calls checkMail() function and gives him text value of email field. Email field is identified by ID email.

Try this script online

Verify email format with PHP

This little PHP function allows you to check if the user wrote a valid email address that may exist. You call this function when you’re checking POST values after form submission.

function validMail($addr) {
if ((!ereg(“.+\@.+\..+”, $addr)) || (!ereg(“^[a-zA-Z0-9_@.-]+$”, $addr)))
RETURN FALSE;
else
RETURN TRUE;
}
// Use :
if(!validMail(‘infoaddress.com’)) {
echo “Your email address is invalid!”;
}

It won’t prove real existence of the email address, but it will avoid the user from writing stupid stuff.

Google Analytics, online statistics

Google Analytics is a free service of Google, which allows you to learn a lot of important information about visitors of your website. If you don’t know it yet, you must get into it as soon as possible!

To know the amount of visitors that come on your website, their origin, where they go and when, is an essential element for the success of your website. To study the behavior of your visitors will help you to improve your website (especially its ergonomy), or at least, to understand what are the problems linked to the user experience your website offers. If you can’t use a more specialised statistic service, I think that Google Analytics would be a very good beginning.

How to add Google Analytics to your website?

Go on Google Analytics‘s website, and suscribe to Google’s online services. If you already own a Gmail account, you may use it for it.

Once you suscribed, click Access Analytics, then Sign up ».

Fill up the form, answer the questions it asks.

Then, Google gives you a javascript code to insert into your HTML pages. You must insert it into ALL your pages, else you won’t get real statistics. With a source editor (Dreamweaver, Golive, etc.), or Notepad, insert the code, just before the closing of the </body> tag (at the end). If you insert it higher in your HTML code, it may slow down your page loading.

The javascript code Google gives you looks like this (don’t use this code, use the one Google gives you) :




After this, you must give Google at least a couple of hours before it starts recording statistics from your website.

Let it go during a couple of days, and then, go back to see what happened. Statistics of a day is accessible only after midnight the same day.

Here is a little trick : In your content stats, you can see what are the pages your visitor go on. It would help you a lot if you would use URL Rewriting for your pages, because it’s a lot easier to recognize which ones are those pages than if they are URLs with many parameters that have no meaning for you.

Now you have to explore Google Analytics as you wish; there are lots of possibilities, only a personal experience of this tool will help you to understand better all its functions.