empty field validation in jquery

前端 未结 2 634
迷失自我
迷失自我 2021-01-25 22:02

I have 3 text fields.

The first field is the only mandatory field, but if the second field is not empty the first and third text field should not be empty.

How

2条回答
  •  孤独总比滥情好
    2021-01-25 22:16

    I think this is a simple logical algorithm

    if ($('#field2').val() != '' && ( $('#field3').val() == '' || $('#field3').val() == '')) {
        return false;
    }
    

    Otherwise, You can find some plugins to validate form there : http://docs.jquery.com/Plugins/Validation

提交回复
热议问题