Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Here is the code in html to allow only one decimal point in a textbox:(这是html中的代码,该文本在文本框中仅允许一个小数点:)

<html> <head> <script type="text/javascript" language="javascript"> function isNumberKey(evt) { var charCode = (evt.charCode) ? evt.which : event.keyCode if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46) return false; else { var input = document.getElementById("txtChar").value; var len = document.getElementById("txtChar").value.length; var index = document.getElementById("txtChar").value.indexOf('.'); if (index > 0 && charCode == 46) { return false; } if (index >0 || index==0) { var CharAfterdot = (len + 1) - index; if (CharAfterdot > 2) { return false; } } if (charCode == 46 && input.split('.').length >1) { return false; } } return true; } </script> </head> <body> <input type="text" id="txtChar" onkeypress="return isNumberKey(event)" name="txtChar" class="CsstxtChar" maxlength="4"/> </body> </html> I want to done this in asp.net using c#.This code is not properly working in asp.net.(我想使用c#在asp.net中完成此操作。此代码无法在asp.net中正常工作。)   ask by Monica translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
389 views
Welcome To Ask or Share your Answers For Others

1 Answer

use this it would be helpful....(使用它会有所帮助。)

$('.urInputField').keyup(function(e){ var val = $(this).val(); var regexTest = /^d{0,8}(.d{1,2})?$/; var ok = regexTest.test(val); if(ok) { $(this).css('background-color', 'green'); } else { $(this).css('background-color', 'red'); } });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...