![]() |
| |||||||
| Sponsored Links |
![]() | « Previous Thread | Next Thread » |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| |||
| |||
| Hi, I have a textbox called insexpdate I want the user to enter valid date format in mm/dd/yyyy format only I call the function onblur event Code:
function callinsexpdate()
{
var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
alert(re);
if((document.frm1.insexpdate.value == "") && (!document.frm1.insexpdate.value.match(re)))
{
alert("Invalid date format");
return false;
}
}
any idea todd |
| Sponsored Links |
|
#2
| ||||
| ||||
| Try this function: Code: function checkdateformat(userinput){
var dateformat = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
return dateformat.test(userinput) //returns true or false depending on userinput
}
__________________ jmurrayhead If you agree with me... click the icon! If my post solved your problem, click the button in the lower right-hand corner of the post.Join our Folding team: DeveloperBarn Folding |
|
#3
| |||
| |||
| @jmh - that will work, but how do you know it's a correct date? It's more complicated than that ![]() I could just type in 2/31/0000 and it will validate ![]() In my opinion, giving users the ability to type in a date is a bad idea as they will make mistakes from time to time. Rather than doing the validation this way, why don't you use a calendar picker. There are plenty out there on the net. Make sure the textbox holding the value is readonly ![]() Then on the serverside, you can validate that it's a correct date (this because you just can't trust users) Besides, it's a good programming practice to always validate input on the server. |
|
#4
| ||||
| ||||
| I completely agree. Just answering the question that was asked. But, to take it one step further, as lewy stated, using a date picker which only allows selection of valid dates would be far better |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| textbox validation | todd2006 | JavaScript Programming | 6 | July 2nd, 2008 01:30 PM |
| checkbox validation | todd2006 | JavaScript Programming | 3 | June 18th, 2008 07:22 PM |
| [ASP.Net/VB.Net] Programmatically Add Item to Validation Summary | jmurrayhead | Code Samples | 0 | March 20th, 2008 09:41 AM |