Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

validar fecha jquery

function isValidDate(dateString)
{
    // revisar el patrón
    if(!/^d{4}-d{1,2}-d{1,2}$/.test(dateString))
        return false;

    // convertir los numeros a enteros
    var parts = dateString.split("/");
    var day = parseInt(parts[2], 10);
    var month = parseInt(parts[1], 10);
    var year = parseInt(parts[0], 10);

    // Revisar los rangos de año y mes
    if( (year < 1000) || (year > 3000) || (month == 0) || (month > 12) )
        return false;

    var monthLength = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];

    // Ajustar para los años bisiestos
    if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))
        monthLength[1] = 29;

    // Revisar el rango del dia
    return day > 0 && day <= monthLength[month - 1];
};


$("button").click(function() {
alert( isValidDate($("#fechaentrega").val()) );
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript Detect Cycle in a Directed Graph 
Javascript :: Another _extend Example 
Javascript :: using condition how to disable radio button in angular 
Javascript :: Babel, env src decrypt, React into javascript in background 
Javascript :: Another _.extend Example 
Javascript :: how to style on-click in react/ vuejs router 
Javascript :: frontend backend communication 
Javascript :: onSeek video getting paused 
Javascript :: get data from json key with special character 
Javascript :: vertical lineal star pattern javascript 
Javascript :: mvc return view with query string 
Javascript :: javascript get minutes between two dates 
Javascript :: sum, rest, ..., ...args 
Javascript :: auto scrolling to end scrollview react native 
Javascript :: before each function 
Javascript :: prisma.db json 
Javascript :: js number power/exponetion 
Javascript :: js to jsx 
Javascript :: hreroku 
Javascript :: create upload preset using node.js on cloudinary 
Javascript :: onClick: share image on Facebook angular 9 
Javascript :: toggling individual item using map in react 
Javascript :: js proxy track nested object 
Javascript :: devlop 
Javascript :: javascript reduce form object 
Javascript :: How to lock thread in javascript energy efficient 
Javascript :: How do i filter name in ng-repeat angularjs 
Javascript :: Automatic display keyed value in a dynamic table row using javascript, angular js and html 
Javascript :: AngularJS slick carousel filter by attribute 
Javascript :: How to hover over data inserted from JSON 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =