This is a migrated thread and some comments may be shown as answers.

Validation Expression for Increment Value on RadNumericTextBox

2 Answers 153 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 18 Oct 2012, 04:09 PM
Hi,
I found the example below that shows how to force the user to enter a number in .5 increments. I need my radnumerictextbox to increment on pack size increments that will vary by item. So in my RadGrid I plan on setting the ValidationExpression on each item during itemdatabind. The bottom line is if the pack size is 24 the box should increment by 24 when the up or down key is hit but also only allow them to type valid increments 24,48,72 etc.
Any idea what the ValidationEpression might look like or is there another way to read the increment setting on the control and only allowing valid increments to get entered? 

<Telerik:RadNumericTextBox ID="txtQtyShp" runat="server" DataType="System.Int" DbValue='<%# Bind("qtyshp") %>'></telerik:RadNumericTextBox>

<asp:RegularExpressionValidator ID="vldQtyShp" runat="server" Display="Dynamic"

ErrorMessage="Please enter valid number." ValidationExpression="^\d+(\.[5])?$"

ControlToValidate="txtQtyShp">

</asp:RegularExpressionValidator>

Thanks,
Tom Usselman

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ErrorMessage="Please enter valid number." ValidationExpression="^\d+(\.[5])?$"

 

ControlToValidate="txtQtyShp">

 

</asp:RegularExpressionValidator>

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 18 Oct 2012, 06:33 PM
Hello,

<telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" MinValue="24" IncrementSettings-Step="24" ShowSpinButtons="true">
           <ClientEvents OnValueChanging="ValueChanging" />
       </telerik:RadNumericTextBox>
function ValueChanging(sender, args) {
               if (args.get_newValue() % 24 != 0) {
                   args.set_cancel(true);
               }


Thanks,
Jayesh Goyani
0
Jeroen
Top achievements
Rank 1
answered on 07 Aug 2013, 05:42 PM

I'm using a RadListView with an RadNumericTextBox for each item.
Every item can have a different IncrementStep, and I needed validation without a hardcoded IncrementStep.
I want to share my code for others with the same requirement:

function numericValueChanging(sender, args) {
    /*extra properties are stored as json value in hidden input*/
    var id = sender._clientStateFieldID;
    var jsonval = $('#' + id).val();
    var jsonobj = $.parseJSON(jsonval);
    /*Because I don't see the incrementstep, I take the minValue*/
    var increment = jsonobj.minValue;
    if (args.get_newValue() % increment != 0) {
        args.set_cancel(true);
    }
}

 

 

 

 

Tags
General Discussions
Asked by
Thomas
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Jeroen
Top achievements
Rank 1
Share this question
or