How to use jQuery to onsubmit and check if the value is 2 - 5 characters?

后端 未结 4 1892
走了就别回头了
走了就别回头了 2020-12-15 21:59

Let\'s say I have a text field:

Username: 

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-15 22:23

    You can check the value of the input field with user.val() and the length of the string with user.val().length.

    That way you can do something like this:

    if(user.val().length < 2 || user.val().length > 5) {
        console.log('test')
    } 
    

提交回复
热议问题