javascript - How to concatenate/change the error message if the input is not a valid date in js? -
i tried 2 days still nothing. maybe can highly skilled in javascript loops.
i asked question before , change code still no luck in showing expected data. , still struggling this.
i have code:
$(function(){ var len = $('#groupcontainer > div').length; var data = []; for(var i=0; < len; i++){ var number = $('#number_' + [i + 1]); var date = $('#date_' + [i + 1]); var count = + 1; var message =""; var = number.map(function(){ return this.value; }); var b = date.map(function(){ return this.value; }); var newobj = {number: a[0], date: b[0]} data.push(newobj); } var message = ""; for(var c = 0; c < data.length; c++) { haveerroringroup = false; for(var d in data[c]) { if(data[c].hasownproperty(d)) { if(data[c][d] == "") { if(!haveerroringroup){ haveerroringroup= true; message += 'group: ' + [c + 1] + '\n'; } message += d + ' required!\n'; } if(d == "date") { if(data[c][d].length != 22 && data[c][d] != "") { message += 'invalid date!\n'; } } } } } if(message){ alert(message); } });
and expected output:
if fields in group 1 filled , group 2 not show alertbox:
group 2: number required! date required!
if field not filled show:
group 1, 2 number required! group 1, 2 date required!
and if date not date:
group 1, 2 date invalid.
and if 1 of inputs invalid.
group 2 date invalid.
if field filled nothing.
here's fiddle
i think looking jquery-validate. i'm pretty sure comes native date validator if want have more specific format can put regex it.
Comments
Post a Comment