-1

for my form validation i wrote a function that split the date in 3 pieces. The pieces are split by "\"

So the date looks like "01\01\2013"

here's my function

function check_date() {

                    var input = $('#start_date').val();
                    var lines = input.split('\\');
                    if (lines[0] <= 31) {
                        $('#start_date').css({'border': '1px solid #b0b0b0'});
                    } else {
                        $('#start_date').css({'border': '1px solid red'});
                    } 
                    if (lines[1] <= 12) {
                        $('#start_date').css({'border': '1px solid #b0b0b0'});
                    } else {
                        $('#start_date').css({'border': '1px solid red'});
                    }

                }

but this doesn't work at all...

is there anyone who can help?

Thx :)

Matt Burland
  • 44,552
  • 18
  • 99
  • 171
MrSkippy
  • 348
  • 4
  • 17

1 Answers1

1

You're splitting by \\ but the date is split by /.

Do you mean input.split('/');?

\\ is equal to a literal backslash character, which would work fine if the date was 01\01\2013.

You say that it was actually \\ but it works fine?

var input = '01\\01\\2013';
var lines = input.split('\\');

if (lines[0] <= 31) {
    console.log('Lines[0] is OK'); //It reaches this
} else {
    console.log('Lines[0] is NOT OK');
}

if (lines[1] <= 12) {
    console.log('Lines[1] is OK'); //It reaches this
} else {
    console.log('Lines[1] is NOT OK');
}
h2ooooooo
  • 39,111
  • 8
  • 68
  • 102