只能输入数字
{
if ([e.keyCode||e.which]==8) //this is to allow backspace
return true;
if ([e.keyCode||e.which] < 48 || [e.keyCode||e.which] > 57)
e.preventDefault? e.preventDefault() : e.returnValue = false;
}
</script>
<input type="text" name="textbox1" id="textbox1" onKeypress='keypress(event)'>
EMail判断
function isEmailFormatValid(emailSrc) {
var email = emailSrc.replace(/^\s+|\s+$/g, '');
if (email == '') {
return false;
}
var regex = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
if (regex.test(email)) {
var str = " !#$%^&*()+=|\{[]}:;'<,>?/" ;
var str2 = '"';
var result = true;
for (var j = 0; j < email.length; j++) {
if (str.indexOf(email.charAt(j)) != -1 || str2.indexOf(email.charAt(j)) != -1) {
result = false;
break;
}
}
if (result == true) {
return true;
}
else {
return false;
}
} else {
return false;
}
}
function btn2_Click() {
var strTest;
if (isEmailFormatValid(document.all['TextBox7'].value) == true)
{
strTest = 'It is ok'
} else {
strTest = 'It is failed'
}
alert(strTest);
}
</script>