validation of input text field in html using javascript

后端 未结 6 1530
鱼传尺愫
鱼传尺愫 2021-02-09 05:22


        
6条回答
  •  时光取名叫无心
    2021-02-09 06:20

    function hasValue( val ) { // Return true if text input is valid/ not-empty
        return val.replace(/\s+/, '').length; // boolean
    }
    

    For multiple elements you can pass inside your input elements loop their value into that function argument.

    If a user inserted one or more spaces, thanks to the regex s+ the function will return false.

提交回复
热议问题