Date not validating as is in UK format

Hi,

I have a form validator on a datepicker. 

The datepicker has format :'dd/MM/yy' ie. UK format.
The validator is set to date:true to make sure the field is a correct data.

However, when I select a date such as 22nd March 2021 - '22/03/2021' the validator returns 'invalid date'. Yet if I change the text to US format '03/22/2021' it validates.

How can i tell the validator to validate UK format dates?

thanks

3 Replies 1 reply marked as answer

JC Joseph Christ Nithin Issack Syncfusion Team March 24, 2021 01:09 PM UTC

Hello Adam, 

Greetings from Syncfusion support. 

We have checked your query. By default the form validator validates the date with the default format of the locale irrespective of the format specified in the datepicker. So, we suggest you to validate the date using the ‘regex’ instead of ‘date’.  Please refer the attached code snippet. 


let datepickerObject: DatePicker = new DatePicker({ 
    // sets the palceholder property. 
    placeholder: 'Enter date', 
    format: 'dd/MM/yyyy' 
}); 
datepickerObject.appendTo('#element'); 
 
let options: FormValidatorModel = { 
    rules: { 
        'datevalue': { regex : [new RegExp("([0-2][0-9]|(3)[0-1])(\/)(((0)[0-9])|((1)[0-2]))(\/)([0-2][0-9][0-9][0-9])]"), "Enter Valid Date"]} 
    }, 
    customPlacement: function (inputElement, errorElement) { 
        //to place the error message in custom position. 
        (<HTMLElement>inputElement).parentElement.parentElement.appendChild(errorElement); 
    } 
} 
let formObject: FormValidator = new FormValidator('#form-element', options); 




Kindly revert us for more queries regarding this. 

Regards, 
Joseph Christ Nithin I 


Marked as answer

AT Adam Toone March 25, 2021 09:22 AM UTC

Great, that works a treat.

Thanks

adam


JM Jeyanth Muthu Pratheeban Sankara Subramanian Syncfusion Team March 26, 2021 05:50 AM UTC

Hi Adam, 

Most Welcome. 

We are glad to hear that your issue has been resolved. Please let us know if you need any further assistance regarding this. 

Regards, 
Jeyanth. 


Loader.
Up arrow icon