Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(function() {
- $(".msgBtn").click(function() {
- var isValid = true;
- if (!$("#startDate").valid()) {
- isValid = false;
- }
- if (!$("#endDate").valid()) {
- isValid = false;
- }
- if (!isValid)
- return;
- $("form#csr-message").submit(); //save button
- });
- });
- $.validator.addMethod(
- "formatdata",
- function(value, element) {
- var i = /(?:0[1-9]|[12][0-9]|3[01]).(?:0[1-9]|1[0-2]).(?:19dd|20dd)/;
- return this.optional(element) || i.test(value);
- }, "Incorrect format data");
- var validator = $("#csr-message")
- .validate(
- {
- rules : {
- startDate : {
- formatdata : true
- },
- endDate : {
- formatdata : true
- }
- },
- messages : {
- startDate : {
- formatdata : jQuery
- .format("Start date has incorrect format!"),
- },
- endDate : {
- formatdata : jQuery
- .format("End date has incorrect format!"),
- }
- }
- }
- $(function () {
- $.datepicker.setDefaults({
- dateFormat: 'dd/mm/yy'
- });
- });
- Then to bind it to the input element:
- $(function () {
- $("#StartDate").datepicker();
- });
- $(document).ready(function () {
- $('#btn_move').click( function(){
- var dateformat = /^(0?[1-9]|[12][0-9]|3[01])[/-](0?[1-9]|1[012])[/-]d{4}$/;
- var Val_date=$('#txt_date').val();
- if(Val_date.match(dateformat)){
- var seperator1 = Val_date.split('/');
- var seperator2 = Val_date.split('-');
- if (seperator1.length>1)
- {
- var splitdate = Val_date.split('/');
- }
- else if (seperator2.length>1)
- {
- var splitdate = Val_date.split('-');
- }
- var dd = parseInt(splitdate[0]);
- var mm = parseInt(splitdate[1]);
- var yy = parseInt(splitdate[2]);
- var ListofDays = [31,28,31,30,31,30,31,31,30,31,30,31];
- if (mm==1 || mm>2)
- {
- if (dd>ListofDays[mm-1])
- {
- alert('Invalid date format!');
- return false;
- }
- }
- if (mm==2)
- {
- var lyear = false;
- if ( (!(yy % 4) && yy % 100) || !(yy % 400))
- {
- lyear = true;
- }
- if ((lyear==false) && (dd>=29))
- {
- alert('Invalid date format!');
- return false;
- }
- if ((lyear==true) && (dd>29))
- {
- alert('Invalid date format!');
- return false;
- }
- }
- }
- else
- {
- alert("Invalid date format!");
- return false;
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement