Jump to content

Date Range Validation


jannasm1

Recommended Posts

i've a form user can enter any date , but i want to set a date range validation so the user can't add a date not in this range . for example: from 1-12-2012 to 1-1-2013 , so if user enter 2-1-2013 the system shouldn't accept it.. i've tried this javascript code but it doesn't work and doesn't give me any alert message even when date not in range .. can you help me with this ? or suggest other javascript code i can use instead

this is part of my form :

 

echo "<th> Date </th>

<td> <input type='date' name='v2' value='' ></td>";

 

and this is the javascript code i've used

<script language="javascript">

 

function validation(form)

{

 

var v2 = document.getElementById('v2');

var date = v2.value;

if ( (v2 > new date('12/12/2012')) &&

(v2 < new date('1/1/2013')) ){

// date is in your valid range

return true;

} else {

// date is not in your valid range

 

alert("date is not in valid range")

return false;

}

 

 

}

 

</script>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.