The RadTextbox accept only numbers and decimail. How to use this validation expression for only accept 2 digits after decimal point. Example: 12.12, 123.23, 1234.12, 12345.67 like this.
I tried 2 ways.
1. ^((?:[1-9]\d*)|(?:(?=[\d.]+)(?:[1-9]\d*|0).\d+))$ --> This expression working fine but i need to accept only two digits after the decimal point.
public void Textbox1_OnTextChanged(object sender, EventArgs e)
{
if (Regex.IsMatch(Textbox1.Text, @"^((?:[1-9]\d*)|(?:(?=[\d.]+)(?:[1-9]\d*|0).\d+))$ "))
{
CalculationSummary();
}
else
{
RadAjaxManager1.Alert("Please enter only numerics.");
}
}
****or****
^(\d+)?+([\.]{1})?+([\d]{1,2})?$ --> This expression working good. It accepts only two digits after the decimal point. but i got error below condition.
public void Textbox1_OnTextChanged(object sender, EventArgs e)
{
if (Regex.IsMatch(Textbox1.Text, @"^(\d+)?+([\.]{1})?+([\d]{1,2})?$"))
{
CalculationSummary();
}
else
{
RadAjaxManager1.Alert("Please enter only numerics.");
}
}
Can anybody please let me know the possible solution. Thanke in advance.
5 Answers, 1 is accepted

that way you could specify DecimalDigits
and Textbox questions belong in Input, not Grid


If you are using RadNumericTextBox you don't need to attach the OnTextChanged event to allow only numbers. RadNumericTextBox restricts user input to numeric values. Please take a look into the sample code.
ASPX:
<
telerik:RadNumericTextBox
ID
=
"RadNumericTextBox1"
runat
=
"server"
>
<
NumberFormat
DecimalDigits
=
"2"
/>
</
telerik:RadNumericTextBox
>
Hope this helps.
Regards,
Princy.

I know its working, I already menctioned in my question. Actually I am doing edit, update delete in RadGrid. In RadGrid i have 10 columns (GridTemplateColumn, all are lables). In insert and update mode i have 8 textboxes and 2 dropdownlists available.
If insert id in the first RadTextBox, basedup id, it will pull records from database and the values assign for 4 textboxes and remaining RadTextBox also have same kind calculation part in OnTextChanged. I run the application (F5).
In application running mode when I hit the tab on keyboard button to go to the next textbox the cursor inside the textbox starts blinks very fast and prevent me from entering number. if i use any TextBox like asp:Textbox or RadTextbox or RadnumericTextbox. Please give me possible solution.
Thanks,
NTR.

Unfortunately I couldn't replicate the issue at my end. Please take a look into the following code snippet I tried.
ASPX:
<
telerik:radgrid
id
=
"RadGrid1"
runat
=
"server"
datasourceid
=
"SqlDataSource1"
autogeneratecolumns
=
"false"
>
<
MasterTableView
InsertItemDisplay
=
"Top"
CommandItemDisplay
=
"Top"
>
<
Columns
>
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:Label
ID
=
"Label1"
runat
=
"server"
Text='<%# Eval("Number1") %>'></
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadNumericTextBox
ID
=
"RadNumericTextBox1"
AutoPostBack
=
"true"
runat
=
"server"
OnTextChanged
=
"RadNumericTextBox1_TextChanged"
>
</
telerik:RadNumericTextBox
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:Label
ID
=
"Label2"
runat
=
"server"
Text='<%# Eval("Number2") %>'></
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadNumericTextBox
ID
=
"RadNumericTextBox2"
AutoPostBack
=
"true"
runat
=
"server"
>
</
telerik:RadNumericTextBox
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:Label
ID
=
"Label3"
runat
=
"server"
Text='<%# Eval("Number3") %>'></
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadNumericTextBox
ID
=
"RadNumericTextBox3"
AutoPostBack
=
"true"
runat
=
"server"
>
</
telerik:RadNumericTextBox
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridButtonColumn
CommandName
=
"Edit"
Text
=
"edit"
>
</
telerik:GridButtonColumn
>
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:Label
ID
=
"Label4"
runat
=
"server"
Text='<%# Eval("Number4") %>'></
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadNumericTextBox
ID
=
"RadNumericTextBox4"
AutoPostBack
=
"true"
runat
=
"server"
>
</
telerik:RadNumericTextBox
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridButtonColumn
CommandName
=
"Edit"
Text
=
"edit"
>
</
telerik:GridButtonColumn
>
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:Label
ID
=
"Label5"
runat
=
"server"
Text='<%# Eval("Number5") %>'></
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadNumericTextBox
ID
=
"RadNumericTextBox5"
AutoPostBack
=
"true"
runat
=
"server"
>
</
telerik:RadNumericTextBox
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridButtonColumn
CommandName
=
"Edit"
Text
=
"edit"
>
</
telerik:GridButtonColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:radgrid
>
C#:
protected
void
RadNumericTextBox1_TextChanged(
object
sender, EventArgs e)
{
GridEditFormItem editItem =(GridEditFormItem)RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem)[0];
RadNumericTextBox num2 = (RadNumericTextBox)editItem.FindControl(
"RadNumericTextBox2"
);
RadNumericTextBox num3 = (RadNumericTextBox)editItem.FindControl(
"RadNumericTextBox3"
);
RadNumericTextBox num4 = (RadNumericTextBox)editItem.FindControl(
"RadNumericTextBox4"
);
num2.Text =
"2"
;
num3.Text =
"3"
;
num4.Text =
"4"
;
}
Please provide your complete code if it doesn't help.
Thanks,
princy.