Loop through all text boxes in a form using jQuery

后端 未结 5 834
予麋鹿
予麋鹿 2020-12-16 18:01

I have a form which is laid out like a spreadsheet.

I want to validate the text in each textbox and if it\'s not numeric, change the background of the textbox and di

5条回答
  •  孤城傲影
    2020-12-16 19:01

    $('form input[type="text"]').each(function(){
            // Do your magic here
            if (this.value.match(/\D/)) // regular expression for numbers only.
                Error();
    });
    

    If you got the form id:

    $('#formId input[type="text"]').each(function(){
            // Do your magic here
    });
    

提交回复
热议问题