在jquery验证文本框中为数字

时间:2015-03-18 12:34:47

标签: javascript jquery html5

仅对数值进行用户ID验证!这是我的代码,请告诉我在我的代码中出错的地方

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 {
}

2 个答案:

答案 0 :(得分:0)

试试这个,

if (parseInt(UserID) > 0) {
   alert("Please enter alphanumeric characters only");
}

答案 1 :(得分:0)

if()$.isNumeric(UserID){

}  else{
alert("not numaric");
}
相关问题