Javascript 在jquery中将文本框验证为数字
仅对数值进行用户ID验证!这是我的代码请告诉我我的代码哪里出错了Javascript 在jquery中将文本框验证为数字,javascript,jquery,html,Javascript,Jquery,Html,仅对数值进行用户ID验证!这是我的代码请告诉我我的代码哪里出错了 function login() { UserID = $('#txtLoginScreen_UserId').val(); password = $('#txtLoginScreen_MPIN').val(); if (UserID.length == 0) { alert("Please enter User ID"); } else if (password.leng
function login() {
UserID = $('#txtLoginScreen_UserId').val();
password = $('#txtLoginScreen_MPIN').val();
if (UserID.length == 0) {
alert("Please enter User ID");
} else if (password.length == 0) {
alert("Please enter MPIN");
}
/* Here am unable to make USer ID validation for restricting only numeric values upto 12 */
/* else if (isNaN(parseInt($("#txtLoginScreen_UserId").val()))) {
alert('It must be numbers');
return false;
}*/
/* Validate for UserID */
/* $("#txtLoginScreen_UserId").keypress(function(e) {
alert("validate");
//if the letter is not digit then display error and don't type anything
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
//display error message
$("#errmsg").html("Digits Only").show().fadeOut("slow");
return false;
}
});
*/
else {
}
试试这个
if (parseInt(UserID) > 0) {
alert("Please enter alphanumeric characters only");
}
我得到了空的验证,这需要一段时间。。但是我需要限制数值,如果使用parseInt,你应该传递一个基数。它仍然不起作用。无论如何,谢谢你的回答。你的代码工作得很好。!我只是修改了你的代码,无法得到正确的东西!这是我修改了相同代码的示例..函数login{UserID=$'txtLoginScreen_UserID'.val;password=$'txtLoginScreen_MPIN'.val;var a=document.getElementById'UserID'.value;ifisana{alert'error ID';}否则{alert'Its Number';}我更改了您的代码,请立即重试,确保UserID var不是空的,并删除一行额外的try now。函数login{UserID=$'txtLoginScreen_UserID'.val;password=$'txtLoginScreen_MPIN'.val;ifisNaNUserID{alert'error ID';}否则{alert'Its Number';}嘿,谢谢它工作正常。。!!关于这一点还有一个小小的疑问。我已经创建了一个登录屏幕,它完全适合所有设备,大多数设备都像htc、三星s3,但在三星s5中,我的页脚将与设备键盘下的登录屏幕用户名和密码重叠。。!!这是一个我无法理解的大问题。。!
if()$.isNumeric(UserID){
} else{
alert("not numaric");
}