'限制只输入数字的话还要考虑输入负号与输入小数点时的情况,我一般是输入结束后判断是否为数据格式:privatesub text1_lostfocus()
iftrim(text1.text)<>""thenifnotisnumeric(text1.text) then
msgbox "请输入数值型数据!",48,"提示"
text1.text=""
text1.setfocus
endifendifend sub
补充一点,不能输入两个小数点 Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> Asc(".") And KeyAscii <> 8 Then KeyAscii = 0 End If If KeyAscii = Asc(".") And InStr(Text1.Text, ".") > 0 and leThen KeyAscii = 0 End If
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title></title><script type="text/javascript">//正整数的验证 function valNum(ev)
{
if(window.event.shiftKey)
{
ev.returnValue ="";
}
else
{
var e = ev.keyCode;
//允许的有大、小键盘的数字,左右键,backspace, delete, Control + C, Control + V if(e !=48&& e !=49&& e !=50&& e !=51&& e !=52&& e !=53&& e !=54&& e !=55&& e !=56&& e !=57&& e !=