验证文本框以仅允许数字和逗号(,) [英] Validating a textbox to allow only numbers and comma (,)

查看:77
本文介绍了验证文本框以仅允许数字和逗号(,)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家。



i有一个文本框,应该只允许数字和逗号(,)



目前我正在使用这个java脚本验证文本框



 function isInteger(evt)
{
var charCode =(evt.which)? evt.which: event .keyCode
if (charCode > 31 &&(charCode < 48 || charCode > 57 ))
返回 false ;
return true ;
}





但如果我复制一些文字并粘贴在文本框中,这种类型的验证将无效



任何人都可以帮我解决这个问题吗?



提前谢谢

解决方案

您好,



请使用以下链接,



http: //www.dotnet-tricks.com/Tutorial/jquery/D9UO110612-Disable-cut,-copy-and-paste-in-textbox-using-jquery,-javascript.html [ ^ ]


最好的选择是使用正则表达式。查看此链接。



https://www.google.co.in/#psj=1&q=regular+expression+in+javascript [ ^ ]



http://regexlib.com/ [ ^ ]


访问此处...



http://social.msdn.microsoft。 com /论坛/ vstudio / zh-CN / 38f835e0-ea8d-4395-8cfc-d63d5514d125 / numeric-value-to-allow-comma-numbers [ ^ ]

< br $> b $ b或



http:// forums.asp.net/t/1901236.aspx [ ^ ]

Hi experts.

i have got a text box it should allow only numbers and comma(,)

Presently am using this java script to validate the textbox

function isInteger(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
             return false;
         return true;
     }



but if i copy some text and paste in the textbox, this type of validation will not work

can any one please help me to solve this issue?

thanks in advance

解决方案

Hi,

Please use the below link,

http://www.dotnet-tricks.com/Tutorial/jquery/D9UO110612-Disable-cut,-copy-and-paste-in-textbox-using-jquery,-javascript.html[^]


Best option would be to use regular expression. Check this links.

https://www.google.co.in/#psj=1&q=regular+expression+in+javascript[^]

http://regexlib.com/[^]


visit here...

http://social.msdn.microsoft.com/Forums/vstudio/en-US/38f835e0-ea8d-4395-8cfc-d63d5514d125/numeric-value-to-allow-comma-numbers[^]

or

http://forums.asp.net/t/1901236.aspx[^]


这篇关于验证文本框以仅允许数字和逗号(,)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆