问题描述
我有数字文本字段,在粘贴一些文本时应验证该文本.
有人可以建议我这样做的方法吗?
我添加了以下代码,以便在用户输入数字时起作用,
< telerik:RadNumericTextBox ID ="_ rdtxtScanNumber" runat =服务器" MinValue ="0" MaxValue ="999999999999999999" NumberFormat-GroupSeparator =" NumberFormat-KeepNotRoundedValue ="False" NumberFormat-DecimalSeparator =" NumberFormat-DecimalDigits ="0 "Width =" 250px>
< ClientEvents OnKeyPress ="ValidateNumber"/>
</telerik:RadNumericTextBox>
并且在ValidateNumber函数中,当用户输入最后一个键时,它将验证数字并可以正常工作.但是在粘贴的情况下将不起作用
I have numeric textfield, on paste of some text it should validate the text.
Can any one suggest me a way for this.
I have added below code to work when a user enter number,
<telerik:RadNumericTextBox ID="_rdtxtScanNumber" runat="server" MinValue="0" MaxValue="999999999999999999" NumberFormat-GroupSeparator="" NumberFormat-KeepNotRoundedValue="False" NumberFormat-DecimalSeparator=" " NumberFormat-DecimalDigits="0" Width="250px" >
<ClientEvents OnKeyPress="ValidateNumber" />
</telerik:RadNumericTextBox>
and in ValidateNumber function when user enter last key, it will validate the number and works fine. but in case of pasting it won''t work
can any one suggest a way to handle this.
推荐答案
function RestrictCopyPaste()
{
var num = clipboardData.getData(''Text'')
if(parseInt(num) != num)
return false;
}
经过测试,可以在所有情况下使用.
Tested and worked for all scenarios.
这篇关于如何验证粘贴事件中的文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!