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");
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)(\/|-|\.)
 date = Convert.ToDateTime(inputstring);
 format = "dd/MM/yyyy";
 string check = date.ToString(format);
 if (regex.IsMatch(check))
     return true;
 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