We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

format string issue

hi,
i cannot find the solution for problem below.
if i have enter the valid format it still throw an error
format = ####.##.####.
allowTextWrap="false"
toolbar="@(new List() { "Add", "Edit", "Delete","ExcelExport"})"
toolbarClick="toolbarClick"
allowPaging="true"
allowSorting="true"
allowReordering="true"
allowSelection="true"
allowGrouping="false"
allowFiltering="true"
allowExcelExport="true"
showColumnMenu="true"
created="created"
allowResizing="true"
load="load"
actionBegin="actionBegin">
allowEditing="true"
allowDeleting="true"
mode="Dialog"
showDeleteConfirmDialog="true">
s
defaultValue="@ViewBag.Guid" showInColumnChooser="false">
defaultValue="@ViewBag.UserId">
isPrimaryKey="true" validationRules="@(new { required = false })"
template="#template3"
defaultValue="@ViewBag.Guid" allowEditing="false" showInColumnChooser="false" isIdentity="true">
}
function load() {
this.columns[0].validationRules = { required: true, length: [customFn, 'should be 12 number only'], format: [myFunction, 'follow the format ####.##.####'], number: [true, 'Required Numeric value'] };
//this.columns[0].format = { type: 'string', format: '####.##.####' };
this.columns[3].format = { type: 'date', format: 'dd/MM/yyyy' }; // set your customize date format based on your column
this.columns[3].validationRules = { required: true, minDate: [myFun1, 'Start Date must less than End Date'] };
this.columns[4].format = { type: 'date', format: 'dd/MM/yyyy' }; // set your customize date format based on your column
this.columns[4].validationRules = { required: true, minDate: [myFun2, 'End Date must greater than Start Date'] };
}
function myFun1(args) {
var entered = args.value.split("/");
var grid = document.getElementById("Grid").ej2_instances[0];
var endDate1 = document.getElementById(grid.element.id + grid.columns[4].field).value;
var enddatesplitted = endDate1.split("/");
if (new Date(entered[1] + '/' + entered[0] + '/' + entered[2]) >= (new Date()).setHours(0, 0, 0, 0)) {
return new Date(entered[1] + '/' + entered[0] + '/' + entered[2]) <= new Date(enddatesplitted[1] + '/' + enddatesplitted[0] + '/' + enddatesplitted[2]);
}
}
function myFun2(args) {
var entered = args.value.split("/");
var grid = document.getElementById("Grid").ej2_instances[0];
var startDate1 = document.getElementById(grid.element.id + grid.columns[3].field).value;
var startDateplitted = startDate1.split("/");
if (new Date(entered[1] + '/' + entered[0] + '/' + entered[2]) >= (new Date()).setHours(0, 0, 0, 0)) {
return new Date(entered[1] + '/' + entered[0] + '/' + entered[2]) >= new Date(startDateplitted[1] + '/' + startDateplitted[0] + '/' + startDateplitted[2]);
}
}
function myFunction(args)
{
return args['value'].format == "9999.99.9999";
}
function customFn(args) {
return args['value'].length == 12;
}

3 Replies

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team October 3, 2019 06:35 AM

Hi Siti,  

Greetings from Syncfusion.  

We could see the custom validation function for the format is not handled properly and you have simply checked its length which is the cause of the problem. We suggest to use the regex to check the required format within the custom function. Refer to the following code example.  

function myFunction(args) 
{ 
 return /\b\d{4}\.\d{2}\.\d{4}\b/.test(args['value']); 
} 
function load(args) { 
  this.columns[0].validationRules = { required: true, length: [customFn, 'should be 12 number only'], format: [myFunction, 'follow the format ####.##.####'] }; 
} 

  
Regards,  
Seeni Sakthi Kumar S 



SE Siti Emayati Murni Saddun Zuber October 4, 2019 04:52 AM

Hai Seeni 
Tq for your respond.it's worked

regards
Ema


SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team October 4, 2019 06:37 AM

Hi Siti,  
  
We are happy to hear that your requirement has been achieved and you are good to go.

Please get back to us, if you require further assistance on this. 
  
Regards,  
Seeni Sakthi Kumar S 


Loader.
Live Chat Icon For mobile
Up arrow icon