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

Regex validation and change date value

Hi team,

Currently am able to show the date with system Dãte.
I want to validate my date picker control to change the decrease date with typing as like -2,-3.. 
If type -2 , my date will change two days back.
 
Query 2. 
Date should not be greater than system date and currently displayed date. 
Ex . Present system date 19-mar-2019
My current date picker 01-mar-2019
If i enter -2 ,it will change to 27-feb-2019. Its should not allow to +1 of current date.

Query 3
 How to apply regex for control for user type.
Should allow only for -ve numbers only

Thanks for the advamce

Sai tanuj


3 Replies

DL Deepa Loganathan Syncfusion Team March 20, 2019 05:20 AM UTC

Hi Sai, 
 
Sorry but, your requirement to update the date value in Datepicker based on numeric input is currently not feasible with Datepicker.  
 
However, it can be achieved as a custom sample but using an additional Textbox. Based on the values updated in Textbox, Datepicker value will be updated in the focusout event. Please let us know if we can proceed to make sample as per the above specification.  
 
Also, please share us the exact requirement for this use case in your application. We will check and provide an optimal solution to meet your requirement.  
 
Thanks,  
Deepa L. 



SK sateesh kumar March 20, 2019 09:43 AM UTC

Hi deepa,

Thanks for the assistance.
i dont want for custom implement ion, for this need to add few elements (check box, text box). test cases will increases for those two controls.

currently, in my date picker user able to press any keys. its plain date picker. no validation. loading date from controller. its custom implement.

after user type any alphabet or any, date picker not holding the user typed text.after tab out from controller its showing my custom implemented date.
Query1

Let us know, how to hold the text after user enter the value date picker.
if the feature is there, easily i can reach my goal.


@Html.EJ().DatePicker("datePick").Value(CustomControls.GetDate()).DateFormat("dd-MM-yyyy").Width("100%")




SI Silambarasan I Syncfusion Team March 21, 2019 09:40 AM UTC

Hi Sai, 
 
We have looked into your query with EJ DatePicker. When you enter an incorrect value other than correct date object or date string, the DatePicker resets the value in the input element to empty string (“”) by default and the model value will not be changed from its previous value.  
 
Since the incorrect value resets null internally before DatePicker events emits, the entered incorrect value (for example: “-1”) will not be obtained from the arguments of focusOut and change event of the DatePicker.  
 
However, to achieve your requirement “how to hold the text after user enter the value date picker” by binding the native onchange event to the input element which will be triggered whenever the value in the input element changes, and this event will trigger before DatePicker’s validation on the entered element. 
 
Please refer the below code snippet to achieve your requirement of holding the entered value in the input element of the DatePicker. 
 
[index.cshtml] 
@{IDictionary<string, object> datepickerHtmlAttribute = new Dictionary<string, object>(); 
    //Binding the onchange event to the input element of the DatePicker using its HtmlAttributes property 
    datepickerHtmlAttribute.Add("onchange", "inputValueChange()"); 
} 
<div id="ControlRegion"> 
    <div class="frame "> 
        <div class="control"> 
            @*Binding the onchange event to the input element of the DatePicker using its HtmlAttributes property*@ 
            @Html.EJ().DatePicker("dateId").HtmlAttributes(datepickerHtmlAttribute) 
        </div> 
    </div> 
    <style> 
        .frame .control { 
            margin-left: 100px; 
        } 
    </style> 
    <script> 
        function inputValueChange() { 
            //By binding the native onchange event to the input element of the DatePicker, 
            //we can get the value entered in the input element 
            var value = document.getElementById("dateId").value; 
            console.log("Value in the input element: " + value); 
        } 
    </script> 
</div> 
 
 
Could you please check the above solution and get back to us if you need any further assistance? 
 
Regards, 
Silambarasan 


Loader.
Live Chat Icon For mobile
Up arrow icon