JS form Email List Validation

Using the JQuery .each() function you can capture if a list of inputs are a proper format.  For this example, we’re checking EACH input with the class value set to requiresEmail.


In the Each statement, you’ll call a function to perform the actual validation.  In this example, I am calling the isValidEmail function and testing the input’s value against the trust regex email validation.

	var OverRide = false;

	function setOverRide(){
		OverRide = true;
	function isValidEmail(Value){
                var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;
		return 	emailPattern.test(Value);
	function CheckEmails(){
		if (OverRide)
			return true;

		returnVal = true;
                   function () {
			if (!isValidEmail($(this).val()))
				$(this).css('background-color', '#f1c7c4');
				returnVal = false;
				$(this).css('background-color', '#fff');

		return returnVal;	

The CheckEmails function should be called to execute the script, and there is a flag to override the validation.

JQuery AJAX Details

The devil is in the details, and the web is no exception. You must keep you user informed each step along the way.

In this post I consider feedback for the customer when performing a single page application call back to the server. When you request is off to the server, use the native CSS Cursor. Set it to Wait, and back to Default when the request is completed, and handled.

CSS to Manipulate the cursor appearance!

 document.body.style.cursor = 'wait'; document.body.style.cursor = 'default'; 

Determining when to change cursor appearance!

The JS Code below determines if the enter or escape key is pressed. Often these keys call for serious actions, and events. This allows you to determine the keyCode and then of course gives you the opportunity to display a good cursor.

// Define the Enter and Escape Keys var KEYCODE_ENTER = 13; var KEYCODE_ESC = 27; 
//check the key pressed, and if it matches, then display the proper cursor 

$(document).keyup(function(e) { 
 if (e.keyCode == KEYCODE_ENTER) { //Change cursor } 
 if (e.keyCode == KEYCODE_ESC) { //Change Cursor } 


php string validation


Common entry validation techniques in PHP using REGEX. PHP Version 5 or later!

Three common strings to validate are Email a Password and Phone number.

In PHP5 or later, using the filter_var function to validate an email address is the quickest and most reliable method to validating an email.

    function isEmail ( $Email ) {
         return filter_var($Email, FILTER_VALIDATE_EMAIL);

Passwords can be defined to follow any format you want. For this reason, it is obviously best to use a customer regular expression to perform the trick. In the example below, the regular expression looks for 8-16 characters using a-z case insensitive, the numbers 0-9, and !@#$_ special characters are allowed.

    function isPassword ( $Password ) {
        return (ereg('^[a-zA-Z0-9!@#$_]{8,16}$', $Password)) ? true : false;

To validate a phone number I find it best to first strip all special characters from an input, then review the number for a specific patter. In the example below, I am validating a number with leading number 2-9 and 9 more numbers 0-9.

    function isPhone($Phone){
        $strippedPhone = ereg_replace("[^0-9]", "", $Phone);
        return (ereg('^[2-9]{1}[0-9]{9}$', $strippedPhone)) ? true : false;

JS FormValidation

The following is a simple collection of String Validation techniques I have commonly used in JavaScript.

Validating an email address with a simple JavaScript Function.

This is a very simple piece of code.  The function checkEmails accepts a arrayChunk with one or two email values.  Then checks if there are two emails, they match.  If they match it checks the format against the regex defined to catch email validity. Return the boolean!

     /* The Function */
	 function checkEmails(arEmail) { 
	 	returnVal = true; 
		var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/; 
		if (arEmail.length == 2 && $('#' + arEmail[0]).val() != $('#' + arEmail[1]).val()) 
			returnVal = false; 
		else if (returnVal && !emailPattern.test($('#' + arEmail[1]).val())) 
			returnVal = false; 
		return returnVal; 
	} /* Call the Function */ checkEmails ( [ Val1, Val2 ] ); 

More of simple queries

You can get the same results as distinct with Count, but Count gives you more value.

Here’s Why!

Consider the following table

x    y    z
a    b    c
a    b    e
a    b    c

If you were to perform a simple query to get the distinct records, you will get 2 results in form the query. In effect, you would receive rows 1 and 2 and the third would be omitted because it was the same as row 1.

The results of the simple distinct query are:

 x   y  z
 a   b   c
 a   b   e

To get more value from the query using Count instead of Distinct write the following query.

select count(*) as count, x,y,z from TableA group by x, y, z

The results you will get will look like this.

count  x   y  z
 2     a   b   c
 1     a   b   e

Now in addition to having the distinct rows found by your query, you have the count of the distinct rows. I like to order by count descending, this way I know what might be the most important.

I found this on SmashingHub.com and it shows the power of simple Queries!


Scheduled Tasks

Scheduled Tasks or Chron Jobs should be managed with the utmost importance. When you Administration pages, or you UI pages fail you get reports from your users immediately. When you tasks fail, you may not get immediate reports.

Here are some things that can be done to ensure your tasks are executed…

  1. Run a beefier computer than your web servers… While you websites handle a lot of requests, you scheduler runs some heavy loads. Also, your processes may be required to run so the rest of your day can run. The UX may be rendered useless if you your scheduled tasks don’t get run, or even don’t finish running.
  2. Run multiple computers. This is simple, two pieces of hardware means hardware backup.
  3. With multiple computers, tier your processes. Keep your beefier machine for heavier processes. Segregate your tasks by priority.
  4. Record Process times for you tasks. If you see a process taking excessive amounts of time, time to revise. Always take some time to revise you apps!
  5. Optimize the heck out of your code to make sure that everything keeps running smoothly. Revisit

Here’s some thoughts in my head, what’s in yours?

Overlooked Marketing

Your email is your biggest FREE and most widely accepted marketing tool. Each time you send an email to a recipient it is read, and your email address is flashed in front of them. They know that an email from you@yourbusiness.com is trusted. Now, If I send 100 emails a day to 10 recipients, then I know that 10 people have seen my brand absolutely today.



Working with Dynamic HTML Elements

With the ever expanding ability to create single page applications for the web we are constantly approaching new problems that must be handled creatively. While our tools become increasingly more capable our browsers do not. One thing that is not handled super cleanly is how jQuery binds to DOM elements or rather how jQuery doesn’t rebind when new elements are added to the DOM.

Consider a single page application that loads an Edit form for a user profile. The new edit form has fields that cannot have auto-binded events to the elements. To make this work, you cannot use the standard jQuery bindings:

 $('.UpdateEmail').keyup(function (e) { /* Perform Work */ } 

You must use the .live() function…

 $('.UpdateEmail').live('keyup', function (e) { /* Perform Work */ } 

The new code is rather simple, move the keyup event handler to the the first paramerter of live, and perform the same work as a second parameter.

Simple htaccess and Site Request Handling.

Hey, so I like my stuff simple as can be. That is why I’ve developed an approach that simplifies my dependency on apache/mod_rewrite/regexes.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

This turns on the apache rewrite engine, handles files, and directories, and then sends EVERYthing to the root index.php file for handling. Now Everything is handled by the more robust server side language than just some regexes.

I put nothing else into the most simple .htaccess file. EVERYthing is easier!

On google alone there are 1.5 million how toos. Keep it simple, keep it like above.