lundi 14 décembre 2015

date format giving error in server in local working fine in MVC

I have a functionality which upload an excel sheet to database. One of the validation is checking then date format given in excel sheet is dd/MM/yyyy

for that i do a regular expression check as below

if (!checkRegex(member["DOB"].ToString().Trim()))
{
  ModelState.AddModelError("DOBFORMAT", "Date of Birth is not in dd/MM/YYYY for record " + count + ". Please check");
System.IO.File.Delete(pathToExcelFile);
return View();
}

and regulare expression checking function is

      public bool checkRegex(string inputstring, string type)
                {
            DateTime date;
           string format;

        Regex regex = new Regex(@"^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]|(?:Jan|Mar|May|Jul|Aug|Oct|Dec)))\1|(?:(?:29|30)(\/|-|\.)
    (?:0?[1,3-9]|1[0-2]|(?:Jan|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec))\2))
    (?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)(?:0?2|(?:Feb))\3
    (?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|
    (?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9]|(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep))|(?:1[0-2]|(?:Oct|Nov|Dec)))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$");
 try
{
 date = Convert.ToDateTime(inputstring);
 format = "dd/MM/yyyy";
 string check = date.ToString(format);
 if (regex.IsMatch(check))
     return true;
else
 return false;
}

when I am uploading an excel sheet with "27/08/1983" from server it is giving error that date format is wrong for the record.

I tried the same with localhost and done debugging. It passed the regular expression and uploaded successfully.

Date format in server and localhost is "dd/MM/yyyy"

Also other excel sheets are uploading successfully.

Please show some light on this issue

Aucun commentaire:

Enregistrer un commentaire