How to validate Date using Javascript Regular Expression

26 Comments

Here is a simple Javascript function to validate a date in US format.

function isDateValid(date) {
	//RegEx to validate date
	/*
	* ^[0-1][1-2] : The month starts with a 0 or 1 followed by either a 1 or a 2
	* [- / ]?: Followed by  an optional "-" or "/".
	* (0[1-9]|[12][0-9]|3[01]) : The day part must be either between 01-09, or 10-29 or 30-31.
	* [- / ]?: Day part will be followed by  an optional "-" or "/".
	* (18|19|20|21)\\d{2}$ : Year begins with either 18, 19, 20 or 21 and ends with two digits.
	*/
	var dateRegExPattern = "^[0-1][1-2][- / ]?(0[1-9]|[12][0-9]|3[01])[- /]?(18|19|20|21)\\d{2}$";
	if(date.match(dateRegExPattern)){
		return true;
	}else{
		return false;
	}
	
}

Get 99% off first month of hosting service fee.

8 Comments

Are you looking for an affordable yet reliable web hosting company? Let me introduce you to eleven2.com. About 5 years ago I moved my website to them and since then I am one of their many happy and satisfied customers. While searching for a web hosting company five years ago to move my blogs from my previous host I stumbled upon eleven2. More

How to redirect homepage in Joomla

5 Comments


Joomla is a wonderful platform to publish websites. With readily available templates you can have your website up and running in no time. Sometimes though you may need to direct your visitors to a different page than your regular home page, for instance you may want to direct all the visitors to a promotion page during special sales events. There is a very simple and easy way of doing this in Joomla. More

Sort numbers in Java to find minimum and maximum values without using Array

35 Comments


Recently a reader contacted me with a question about sorting numbers in Java. After sorting the number the program then needs to print the largest and smallest values. I have written a post earlier that shows one way of finding largest and smallest numbers. That approach used Arrays but the reader wanted to find largest and smallest values from a group of numbers without using Arrays. So here is another approach.

This program accepts input from the user and then prints out the largest and smallest numbers.






import java.util.*; 
public class NumberSorter{
	public static void main(String args[]){
	  double a, b, c, x, y;
	  Scanner console = new Scanner(System.in); 
	  System.out.print("Enter the first number: " ); 
	  a = console.nextDouble() ;
	  System.out.print("Enter the second number: " ); 
	  b  = console.nextDouble() ;
	  System.out.print("Enter the third number: " ); 
	  c = console.nextDouble();
	  x= Math.min(a, Math.min(b, c));
	  y= Math.max(a, Math.max(b, c));
	  System.out.println("\n" +x + " is the smallest number.\n" + y 
	                     +" is the largest number.");
	}
}

Hope you find this useful. Share your ideas on how else can we find largest and smallest values from a group of numbers Java.

Java String comparison. The difference between == and equals().

33 Comments

Many Java beginners find it difficult to differentiate between == operator and the “equals()” method when comparing String variables in Java. They assume that both operations perform the same function and either one can be used to compare two string variables. I have even seen many experienced programmers committing the mistake of using “==” to compare the values of two strings.

So what is the difference between “==” and “equals()” and what is the correct method of comparing two string variables?
More

An HTML element you don't want to omit.

2 Comments

Various Doctypes

Doctypes

As web developers we have the tendency to blame web browsers for inconsistencies and for not displaying the pages as designed. Most of the time the blame is justified, but there are instances when the blame lies at the feet of the web developers. For example, incorrect CSS declarations, missing closing tags in HTML documents will break you website. Another common and often overlooked reason of broken web pages is the missing or incorrect DOCYTYPE declaration. More

A fresh new look.

2 Comments

Welcome to redesigned and improved zParacha.com. I have been thinking of giving my blog a face-lift for some time. I considered several options including designing/developing a new theme from scratch, buying Thesis and then modifying it, or buying a premium theme. Since I have several options I kept considering pros and cons of each one and in the process the planned upgrade was delayed. Basically I was just procrastinating.

Finally, I decided to get it down and settled on this elegant, free premium theme. I am still working on some minor customization but I believe this is a nice, professional-looking theme that meets my requirements.

Share your thoughts on this new design. Do you like the color scheme, page layout? What do you not like? What elements do you think I can change to further improve the look?

Why you should stop using onload method.

9 Comments

Onload

Onload

It is amazing that many web developers still use onload method embedded in the BODY tag, like


 <HEAD>
 <BODY onload="document.contact.userID.focus();">
  <form name="contact">
   <input type="text" name="userID" >
  </form>
  </BODY>
 </HEAD>

There are two problems with this line of code.

  1. Embedding code (behavior) with HTML (structure) makes it difficult to maintain the page.
  2. onload() method will executes only after the page is fully displayed.
  3. Let’s see how to fix these problems. More

Google says Adios to IE6.

3 Comments


Google agrees that the time has come for us to lay IE6 to rest. Google announced in a blog post that it will stop supporting IE6 from March 01, 2010. Google will start by phasing out IE6 support for Google Docs and Google Sites, but I believe eventually all Google products will stop supporting IE6.
More

Five free tools to choose perfect colors for your website.

19 Comments

Rainbow colors


Color coordination plays a big role in the look and feel of a website. An appealing color scheme is an important prerequisite for eye catching web design. Dull or very sharp colors or mismatch colors will not only look ugly it may overshadow other nice elements of your website. Choosing vibrant, harmonious colors that are pleasant to eyes enhance the aesthetics appeal of a website. Following is a list of online resources you can use to construct the color schemes for your next web design project.
More

Older Entries