如何限制用户在C#中输入texbox中的白色spces [英] How to restrict user from entering white spces in the texbox in C#
本文介绍了如何限制用户在C#中输入texbox中的白色spces的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本框,它只使用以下正则表达式接受数字和小数点:
正则表达式reg =新正则表达式([^ [0-9。 ] +);
所以我现在如何限制用户在文本框中输入空格(在开头) C#?
请有人能为我提供解决方案吗?
I have a textbox which accepts only numeric and decimal point using the following regular expressions :
Regex reg = new Regex("[^[0-9.]+");
so now how can i restrict user from entering white spaces(in the beginning) in the text box using C#?
please can anyone provide me a solution?
推荐答案
写下javascrip函数
函数isNumberKey( txt,e){
var arr =0123456789。;
var code;
if(window.event)
code = e.keyCode;
else
code = e.which;
var char = keychar = String.fromCharCode(代码);
if(arr.indexOf(char)== -1)
返回false;
else if(char ==。)
if(txt.value.indexOf(。)> -1)
return false;
}
并在onkeypreess事件中调用此函数
onkeypress =return isNumberKey(this,event)
Write below javascrip function
function isNumberKey(txt, e) {
var arr = "0123456789.";
var code;
if (window.event)
code = e.keyCode;
else
code = e.which;
var char = keychar = String.fromCharCode(code);
if (arr.indexOf(char) == -1)
return false;
else if (char == ".")
if (txt.value.indexOf(".") > -1)
return false;
}
and call this function on onkeypreess event
onkeypress = "return isNumberKey(this,event)"
使用下面的脚本。
use the below script.
( function (){
var txt =
(function() { var txt =
这篇关于如何限制用户在C#中输入texbox中的白色spces的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文